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,2279 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Femo Syntax Reference</title>
|
|
7
|
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
8
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
9
|
+
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,300;0,400;0,500;1,300&family=IBM+Plex+Sans:wght@300;400;500;600&display=swap" rel="stylesheet">
|
|
10
|
+
<style>
|
|
11
|
+
:root {
|
|
12
|
+
--bg: #111210;
|
|
13
|
+
--bg2: #181917;
|
|
14
|
+
--bg3: #1f201e;
|
|
15
|
+
--bg4: #252624;
|
|
16
|
+
--border: rgba(255,255,255,0.07);
|
|
17
|
+
--border2: rgba(255,255,255,0.12);
|
|
18
|
+
--gold: #c8a84b;
|
|
19
|
+
--gold2: #a07e2e;
|
|
20
|
+
--gold-bg: rgba(200,168,75,0.08);
|
|
21
|
+
--green: #6aaa64;
|
|
22
|
+
--blue: #79b8d4;
|
|
23
|
+
--purple: #c586c0;
|
|
24
|
+
--orange: #e8905a;
|
|
25
|
+
--red: #d06060;
|
|
26
|
+
--text1: #e8e4d8;
|
|
27
|
+
--text2: #a89e88;
|
|
28
|
+
--text3: #5e5a52;
|
|
29
|
+
--sidebar-w: 272px;
|
|
30
|
+
--mono: 'IBM Plex Mono', monospace;
|
|
31
|
+
--sans: 'IBM Plex Sans', sans-serif;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
* { margin:0; padding:0; box-sizing:border-box; }
|
|
35
|
+
html { scroll-behavior: smooth; font-size: 15px; }
|
|
36
|
+
|
|
37
|
+
body {
|
|
38
|
+
background: var(--bg);
|
|
39
|
+
color: var(--text1);
|
|
40
|
+
font-family: var(--sans);
|
|
41
|
+
line-height: 1.7;
|
|
42
|
+
display: flex;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* ─── Scrollbar ─── */
|
|
46
|
+
::-webkit-scrollbar { width: 5px; height: 5px; }
|
|
47
|
+
::-webkit-scrollbar-track { background: var(--bg2); }
|
|
48
|
+
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 2px; }
|
|
49
|
+
::-webkit-scrollbar-thumb:hover { background: var(--text3); }
|
|
50
|
+
|
|
51
|
+
/* ─── Sidebar ─── */
|
|
52
|
+
#sidebar {
|
|
53
|
+
position: fixed; top: 0; left: 0; bottom: 0;
|
|
54
|
+
width: var(--sidebar-w);
|
|
55
|
+
background: var(--bg2);
|
|
56
|
+
border-right: 1px solid var(--border);
|
|
57
|
+
overflow-y: auto;
|
|
58
|
+
display: flex; flex-direction: column;
|
|
59
|
+
z-index: 50;
|
|
60
|
+
transition: transform 0.3s ease;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.sidebar-header {
|
|
64
|
+
padding: 1.6rem 1.4rem 1.2rem;
|
|
65
|
+
border-bottom: 1px solid var(--border);
|
|
66
|
+
flex-shrink: 0;
|
|
67
|
+
}
|
|
68
|
+
.sidebar-logo {
|
|
69
|
+
font-family: var(--mono); font-size: 0.85rem; font-weight: 500;
|
|
70
|
+
color: var(--gold); letter-spacing: 0.08em;
|
|
71
|
+
}
|
|
72
|
+
.sidebar-sub {
|
|
73
|
+
font-size: 0.7rem; color: var(--text3); margin-top: 0.25rem;
|
|
74
|
+
font-family: var(--mono);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.sidebar-search {
|
|
78
|
+
padding: 0.8rem 1rem;
|
|
79
|
+
border-bottom: 1px solid var(--border);
|
|
80
|
+
flex-shrink: 0;
|
|
81
|
+
}
|
|
82
|
+
.sidebar-search input {
|
|
83
|
+
width: 100%; background: var(--bg3); border: 1px solid var(--border2);
|
|
84
|
+
color: var(--text1); padding: 0.45rem 0.7rem;
|
|
85
|
+
font-family: var(--mono); font-size: 0.72rem;
|
|
86
|
+
outline: none; border-radius: 3px;
|
|
87
|
+
transition: border-color 0.2s;
|
|
88
|
+
}
|
|
89
|
+
.sidebar-search input:focus { border-color: var(--gold2); }
|
|
90
|
+
.sidebar-search input::placeholder { color: var(--text3); }
|
|
91
|
+
|
|
92
|
+
nav#toc {
|
|
93
|
+
padding: 0.8rem 0; flex: 1;
|
|
94
|
+
overflow-y: auto;
|
|
95
|
+
}
|
|
96
|
+
.toc-group { margin-bottom: 0.3rem; }
|
|
97
|
+
.toc-group-label {
|
|
98
|
+
font-family: var(--mono); font-size: 0.6rem; letter-spacing: 0.2em;
|
|
99
|
+
color: var(--text3); text-transform: uppercase;
|
|
100
|
+
padding: 0.5rem 1.4rem 0.3rem;
|
|
101
|
+
}
|
|
102
|
+
.toc-link {
|
|
103
|
+
display: flex; align-items: center; gap: 0.5rem;
|
|
104
|
+
padding: 0.38rem 1.4rem; font-size: 0.78rem; color: var(--text2);
|
|
105
|
+
text-decoration: none; transition: color 0.15s, background 0.15s;
|
|
106
|
+
border-left: 2px solid transparent; cursor: pointer;
|
|
107
|
+
}
|
|
108
|
+
.toc-link:hover { color: var(--text1); background: var(--bg3); }
|
|
109
|
+
.toc-link.active { color: var(--gold); border-left-color: var(--gold); background: var(--gold-bg); }
|
|
110
|
+
.toc-link .toc-num {
|
|
111
|
+
font-family: var(--mono); font-size: 0.62rem; color: var(--text3);
|
|
112
|
+
min-width: 1.6em; flex-shrink: 0;
|
|
113
|
+
}
|
|
114
|
+
.toc-sub { padding-left: 3.2rem; font-size: 0.73rem; }
|
|
115
|
+
|
|
116
|
+
/* ─── Main ─── */
|
|
117
|
+
#main {
|
|
118
|
+
margin-left: var(--sidebar-w);
|
|
119
|
+
flex: 1; min-width: 0;
|
|
120
|
+
padding: 0 0 6rem;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/* ─── Top bar ─── */
|
|
124
|
+
#topbar {
|
|
125
|
+
position: sticky; top: 0; z-index: 40;
|
|
126
|
+
background: rgba(17,18,16,0.92);
|
|
127
|
+
backdrop-filter: blur(12px);
|
|
128
|
+
border-bottom: 1px solid var(--border);
|
|
129
|
+
padding: 0.7rem 3rem;
|
|
130
|
+
display: flex; align-items: center; justify-content: space-between;
|
|
131
|
+
}
|
|
132
|
+
.topbar-path {
|
|
133
|
+
font-family: var(--mono); font-size: 0.72rem; color: var(--text3);
|
|
134
|
+
display: flex; align-items: center; gap: 0.4rem;
|
|
135
|
+
}
|
|
136
|
+
.topbar-path span { color: var(--text2); }
|
|
137
|
+
.topbar-actions { display: flex; gap: 0.8rem; }
|
|
138
|
+
.topbar-btn {
|
|
139
|
+
font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.05em;
|
|
140
|
+
color: var(--text3); padding: 0.3rem 0.8rem;
|
|
141
|
+
border: 1px solid var(--border2); background: transparent;
|
|
142
|
+
cursor: pointer; transition: color 0.15s, border-color 0.15s;
|
|
143
|
+
text-decoration: none; display: inline-block;
|
|
144
|
+
}
|
|
145
|
+
.topbar-btn:hover { color: var(--text1); border-color: var(--text3); }
|
|
146
|
+
|
|
147
|
+
/* ─── Content ─── */
|
|
148
|
+
#content {
|
|
149
|
+
max-width: 880px;
|
|
150
|
+
padding: 3rem 3rem 0;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/* ─── Doc sections ─── */
|
|
154
|
+
.doc-section {
|
|
155
|
+
margin-bottom: 4.5rem;
|
|
156
|
+
opacity: 0; transform: translateY(16px);
|
|
157
|
+
transition: opacity 0.4s ease, transform 0.4s ease;
|
|
158
|
+
}
|
|
159
|
+
.doc-section.visible { opacity: 1; transform: translateY(0); }
|
|
160
|
+
|
|
161
|
+
.section-anchor { display: block; height: 80px; margin-top: -80px; visibility: hidden; }
|
|
162
|
+
|
|
163
|
+
.section-header {
|
|
164
|
+
display: flex; align-items: baseline; gap: 0.8rem;
|
|
165
|
+
margin-bottom: 1.4rem; padding-bottom: 0.8rem;
|
|
166
|
+
border-bottom: 1px solid var(--border);
|
|
167
|
+
}
|
|
168
|
+
.section-num {
|
|
169
|
+
font-family: var(--mono); font-size: 0.65rem; color: var(--text3);
|
|
170
|
+
letter-spacing: 0.1em; padding-top: 0.15rem;
|
|
171
|
+
}
|
|
172
|
+
.section-title {
|
|
173
|
+
font-size: 1.25rem; font-weight: 600; color: var(--text1);
|
|
174
|
+
letter-spacing: -0.01em;
|
|
175
|
+
}
|
|
176
|
+
.section-badge {
|
|
177
|
+
font-family: var(--mono); font-size: 0.58rem; letter-spacing: 0.15em;
|
|
178
|
+
text-transform: uppercase; padding: 0.15rem 0.5rem;
|
|
179
|
+
border: 1px solid; border-radius: 2px; margin-left: auto;
|
|
180
|
+
white-space: nowrap;
|
|
181
|
+
}
|
|
182
|
+
.badge-core { color: var(--gold); border-color: var(--gold2); }
|
|
183
|
+
.badge-flow { color: var(--blue); border-color: #4a7a90; }
|
|
184
|
+
.badge-adv { color: var(--purple);border-color: #7a4a80; }
|
|
185
|
+
.badge-debug { color: var(--red); border-color: #8a3a3a; }
|
|
186
|
+
|
|
187
|
+
/* ─── Prose ─── */
|
|
188
|
+
p { color: var(--text2); margin-bottom: 1rem; line-height: 1.85; }
|
|
189
|
+
p strong { color: var(--text1); font-weight: 500; }
|
|
190
|
+
p em { color: var(--gold); font-style: normal; }
|
|
191
|
+
|
|
192
|
+
ul, ol { color: var(--text2); padding-left: 1.4rem; margin-bottom: 1rem; }
|
|
193
|
+
li { margin-bottom: 0.35rem; line-height: 1.75; }
|
|
194
|
+
li strong { color: var(--text1); }
|
|
195
|
+
li code { font-family: var(--mono); font-size: 0.82em; color: var(--blue);
|
|
196
|
+
background: rgba(121,184,212,0.1); padding: 0.1em 0.35em; border-radius: 2px; }
|
|
197
|
+
|
|
198
|
+
/* ─── Callout boxes ─── */
|
|
199
|
+
.callout {
|
|
200
|
+
display: flex; gap: 0.8rem; align-items: flex-start;
|
|
201
|
+
padding: 0.9rem 1.1rem; border-radius: 3px;
|
|
202
|
+
margin: 1.2rem 0; border-left: 3px solid;
|
|
203
|
+
}
|
|
204
|
+
.callout-icon { font-size: 0.9rem; flex-shrink: 0; padding-top: 0.1rem; }
|
|
205
|
+
.callout-body { font-size: 0.85rem; color: var(--text2); line-height: 1.75; }
|
|
206
|
+
.callout-body strong { color: var(--text1); }
|
|
207
|
+
.callout-body code { font-family: var(--mono); font-size: 0.8em; color: inherit;
|
|
208
|
+
background: rgba(255,255,255,0.06); padding: 0.1em 0.3em; border-radius: 2px; }
|
|
209
|
+
.callout.tip { background: rgba(106,170,100,0.06); border-color: var(--green); }
|
|
210
|
+
.callout.warn { background: rgba(200,168,75,0.06); border-color: var(--gold); }
|
|
211
|
+
.callout.danger { background: rgba(208,96,96,0.06); border-color: var(--red); }
|
|
212
|
+
.callout.info { background: rgba(121,184,212,0.06); border-color: var(--blue); }
|
|
213
|
+
|
|
214
|
+
/* ─── Code blocks ─── */
|
|
215
|
+
.code-block {
|
|
216
|
+
position: relative; margin: 1.4rem 0;
|
|
217
|
+
background: var(--bg3); border: 1px solid var(--border);
|
|
218
|
+
border-radius: 4px; overflow: hidden;
|
|
219
|
+
}
|
|
220
|
+
.code-header {
|
|
221
|
+
display: flex; align-items: center; justify-content: space-between;
|
|
222
|
+
padding: 0.5rem 1rem; background: var(--bg4);
|
|
223
|
+
border-bottom: 1px solid var(--border);
|
|
224
|
+
}
|
|
225
|
+
.code-lang {
|
|
226
|
+
font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.15em;
|
|
227
|
+
text-transform: uppercase; color: var(--text3);
|
|
228
|
+
}
|
|
229
|
+
.code-copy {
|
|
230
|
+
font-family: var(--mono); font-size: 0.62rem; color: var(--text3);
|
|
231
|
+
cursor: pointer; transition: color 0.15s; background: none; border: none;
|
|
232
|
+
padding: 0.15rem 0.4rem; letter-spacing: 0.05em;
|
|
233
|
+
}
|
|
234
|
+
.code-copy:hover { color: var(--gold); }
|
|
235
|
+
.code-copy.copied { color: var(--green); }
|
|
236
|
+
pre {
|
|
237
|
+
padding: 1.1rem 1.2rem; overflow-x: auto;
|
|
238
|
+
font-family: var(--mono); font-size: 0.8rem; line-height: 1.85;
|
|
239
|
+
color: var(--text2);
|
|
240
|
+
}
|
|
241
|
+
/* Syntax tokens */
|
|
242
|
+
.k { color: var(--orange); }
|
|
243
|
+
.at { color: var(--gold); }
|
|
244
|
+
.s { color: var(--green); }
|
|
245
|
+
.c { color: var(--text3); font-style: italic; }
|
|
246
|
+
.v { color: var(--blue); }
|
|
247
|
+
.p { color: var(--purple); }
|
|
248
|
+
.n { color: var(--text1); }
|
|
249
|
+
.f { color: var(--text1); }
|
|
250
|
+
|
|
251
|
+
/* ─── Table ─── */
|
|
252
|
+
.table-wrap {
|
|
253
|
+
overflow-x: auto; margin: 1.2rem 0;
|
|
254
|
+
border: 1px solid var(--border); border-radius: 4px;
|
|
255
|
+
}
|
|
256
|
+
table { width: 100%; border-collapse: collapse; font-size: 0.83rem; }
|
|
257
|
+
th {
|
|
258
|
+
background: var(--bg4); color: var(--text2);
|
|
259
|
+
font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.1em;
|
|
260
|
+
text-transform: uppercase; font-weight: 500;
|
|
261
|
+
padding: 0.6rem 1rem; text-align: left;
|
|
262
|
+
border-bottom: 1px solid var(--border2);
|
|
263
|
+
}
|
|
264
|
+
td {
|
|
265
|
+
padding: 0.6rem 1rem; color: var(--text2);
|
|
266
|
+
border-bottom: 1px solid var(--border); vertical-align: top;
|
|
267
|
+
}
|
|
268
|
+
tr:last-child td { border-bottom: none; }
|
|
269
|
+
td code, th code {
|
|
270
|
+
font-family: var(--mono); font-size: 0.8em; color: var(--blue);
|
|
271
|
+
background: rgba(121,184,212,0.1); padding: 0.1em 0.3em; border-radius: 2px;
|
|
272
|
+
}
|
|
273
|
+
td strong { color: var(--text1); }
|
|
274
|
+
|
|
275
|
+
/* ─── Def grid ─── */
|
|
276
|
+
.def-grid {
|
|
277
|
+
display: grid; grid-template-columns: auto 1fr;
|
|
278
|
+
border: 1px solid var(--border); border-radius: 4px;
|
|
279
|
+
overflow: hidden; margin: 1.2rem 0;
|
|
280
|
+
}
|
|
281
|
+
.def-term {
|
|
282
|
+
font-family: var(--mono); font-size: 0.75rem; font-weight: 500;
|
|
283
|
+
color: var(--gold); padding: 0.6rem 1rem;
|
|
284
|
+
background: var(--bg4); border-bottom: 1px solid var(--border);
|
|
285
|
+
white-space: nowrap;
|
|
286
|
+
}
|
|
287
|
+
.def-desc {
|
|
288
|
+
font-size: 0.83rem; color: var(--text2); padding: 0.6rem 1rem;
|
|
289
|
+
background: var(--bg2); border-bottom: 1px solid var(--border);
|
|
290
|
+
line-height: 1.65;
|
|
291
|
+
}
|
|
292
|
+
.def-term:last-of-type, .def-desc:last-of-type { border-bottom: none; }
|
|
293
|
+
.def-desc code {
|
|
294
|
+
font-family: var(--mono); font-size: 0.8em; color: var(--blue);
|
|
295
|
+
background: rgba(121,184,212,0.1); padding: 0.1em 0.3em; border-radius: 2px;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/* ─── Sub-section heading ─── */
|
|
299
|
+
h3.sub {
|
|
300
|
+
font-size: 1rem; font-weight: 600; color: var(--text1);
|
|
301
|
+
margin: 2.2rem 0 0.8rem;
|
|
302
|
+
display: flex; align-items: center; gap: 0.5rem;
|
|
303
|
+
}
|
|
304
|
+
h3.sub::before {
|
|
305
|
+
content: ''; display: inline-block;
|
|
306
|
+
width: 3px; height: 1em;
|
|
307
|
+
background: var(--gold); border-radius: 1px;
|
|
308
|
+
}
|
|
309
|
+
h4.sub2 {
|
|
310
|
+
font-size: 0.9rem; font-weight: 500; color: var(--text2);
|
|
311
|
+
margin: 1.6rem 0 0.6rem; letter-spacing: 0.01em;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/* ─── Highlight ─── */
|
|
315
|
+
.hl { color: var(--gold); font-family: var(--mono); font-size: 0.85em;
|
|
316
|
+
background: var(--gold-bg); padding: 0.1em 0.35em; border-radius: 2px; }
|
|
317
|
+
|
|
318
|
+
/* ─── Two-col ─── */
|
|
319
|
+
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: 1.2rem 0; }
|
|
320
|
+
.two-col .code-block { margin: 0; }
|
|
321
|
+
|
|
322
|
+
/* ─── Divider ─── */
|
|
323
|
+
hr { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }
|
|
324
|
+
|
|
325
|
+
/* ─── Anchor link ─── */
|
|
326
|
+
a { color: var(--gold); text-decoration: none; }
|
|
327
|
+
a:hover { text-decoration: underline; }
|
|
328
|
+
|
|
329
|
+
/* ─── Progress bar ─── */
|
|
330
|
+
#progress {
|
|
331
|
+
position: fixed; top: 0; left: var(--sidebar-w); right: 0;
|
|
332
|
+
height: 2px; background: transparent; z-index: 100;
|
|
333
|
+
}
|
|
334
|
+
#progress-bar {
|
|
335
|
+
height: 100%; background: var(--gold); width: 0;
|
|
336
|
+
transition: width 0.1s linear;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/* ─── Mobile toggle ─── */
|
|
340
|
+
#menu-toggle {
|
|
341
|
+
display: none; position: fixed; bottom: 1.5rem; right: 1.5rem;
|
|
342
|
+
background: var(--gold); color: var(--bg); border: none;
|
|
343
|
+
width: 44px; height: 44px; border-radius: 50%;
|
|
344
|
+
font-size: 1.1rem; cursor: pointer; z-index: 200;
|
|
345
|
+
box-shadow: 0 4px 16px rgba(0,0,0,0.4);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
@media (max-width: 768px) {
|
|
349
|
+
#sidebar { transform: translateX(-100%); }
|
|
350
|
+
#sidebar.open { transform: translateX(0); }
|
|
351
|
+
#main { margin-left: 0; }
|
|
352
|
+
#progress { left: 0; }
|
|
353
|
+
#content { padding: 2rem 1.2rem 0; }
|
|
354
|
+
#topbar { padding: 0.7rem 1.2rem; }
|
|
355
|
+
.two-col { grid-template-columns: 1fr; }
|
|
356
|
+
#menu-toggle { display: flex; align-items: center; justify-content: center; }
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/* ─── Animation ─── */
|
|
360
|
+
.anim-wrap {
|
|
361
|
+
margin: 1.4rem 0;
|
|
362
|
+
background: var(--bg3);
|
|
363
|
+
border: 1px solid var(--border);
|
|
364
|
+
border-radius: 4px;
|
|
365
|
+
overflow: hidden;
|
|
366
|
+
padding: 1.2rem 1rem 0.8rem;
|
|
367
|
+
}
|
|
368
|
+
.anim-wrap canvas {
|
|
369
|
+
display: block;
|
|
370
|
+
max-width: 100%;
|
|
371
|
+
height: auto;
|
|
372
|
+
}
|
|
373
|
+
.anim-controls {
|
|
374
|
+
display: flex;
|
|
375
|
+
justify-content: flex-end;
|
|
376
|
+
padding: 0.5rem 0.2rem 0;
|
|
377
|
+
}
|
|
378
|
+
.anim-btn {
|
|
379
|
+
font-family: var(--mono);
|
|
380
|
+
font-size: 0.68rem;
|
|
381
|
+
letter-spacing: 0.05em;
|
|
382
|
+
color: var(--text3);
|
|
383
|
+
background: none;
|
|
384
|
+
border: 1px solid var(--border2);
|
|
385
|
+
padding: 0.25rem 0.7rem;
|
|
386
|
+
cursor: pointer;
|
|
387
|
+
transition: color 0.15s, border-color 0.15s;
|
|
388
|
+
}
|
|
389
|
+
.anim-btn:hover { color: var(--gold); border-color: var(--gold2); }
|
|
390
|
+
</style>
|
|
391
|
+
</head>
|
|
392
|
+
<body>
|
|
393
|
+
|
|
394
|
+
<!-- Progress bar -->
|
|
395
|
+
<div id="progress"><div id="progress-bar"></div></div>
|
|
396
|
+
|
|
397
|
+
<!-- Sidebar -->
|
|
398
|
+
<aside id="sidebar">
|
|
399
|
+
<div class="sidebar-header">
|
|
400
|
+
<div class="sidebar-logo">Femo Docs</div>
|
|
401
|
+
<div class="sidebar-sub">Syntax Reference · v1.0</div>
|
|
402
|
+
</div>
|
|
403
|
+
<div class="sidebar-search">
|
|
404
|
+
<input type="text" id="search-input" placeholder="Search docs…" autocomplete="off">
|
|
405
|
+
</div>
|
|
406
|
+
<nav id="toc">
|
|
407
|
+
<div class="toc-group">
|
|
408
|
+
<div class="toc-group-label">Getting Started</div>
|
|
409
|
+
<a class="toc-link" href="#s-overview"><span class="toc-num">00</span>Overview & Design Philosophy</a>
|
|
410
|
+
<a class="toc-link" href="#s-structure"><span class="toc-num">01</span>File Structure</a>
|
|
411
|
+
<a class="toc-link" href="#s-conventions"><span class="toc-num">02</span>Conventions & Symbols</a>
|
|
412
|
+
</div>
|
|
413
|
+
<div class="toc-group">
|
|
414
|
+
<div class="toc-group-label">Core Syntax</div>
|
|
415
|
+
<a class="toc-link" href="#s-meta"><span class="toc-num">03</span>meta — Script Metadata</a>
|
|
416
|
+
<a class="toc-link" href="#s-vars"><span class="toc-num">04</span>vars — Variable Pool</a>
|
|
417
|
+
<a class="toc-link" href="#s-actors"><span class="toc-num">05</span>actors — Role Definitions</a>
|
|
418
|
+
<a class="toc-link" href="#s-code"><span class="toc-num">06</span>code — External Modules</a>
|
|
419
|
+
<a class="toc-link" href="#s-memory"><span class="toc-num">07</span>memory & context</a>
|
|
420
|
+
</div>
|
|
421
|
+
<div class="toc-group">
|
|
422
|
+
<div class="toc-group-label">Actions</div>
|
|
423
|
+
<a class="toc-link" href="#s-action-ai"><span class="toc-num">08</span>AI Action @ai</a>
|
|
424
|
+
<a class="toc-link" href="#s-action-human"><span class="toc-num">09</span>Human Action @human</a>
|
|
425
|
+
<a class="toc-link" href="#s-action-assign"><span class="toc-num">10</span>Assignment Action @assign</a>
|
|
426
|
+
<a class="toc-link" href="#s-action-func"><span class="toc-num">11</span>Function Call @func</a>
|
|
427
|
+
</div>
|
|
428
|
+
<div class="toc-group">
|
|
429
|
+
<div class="toc-group-label">Flow Orchestration</div>
|
|
430
|
+
<a class="toc-link" href="#s-flow-basic"><span class="toc-num">12</span>Basic Chain Flow</a>
|
|
431
|
+
<a class="toc-link" href="#s-flow-fork"><span class="toc-num">13</span>Concurrent Fork</a>
|
|
432
|
+
<a class="toc-link" href="#s-flow-join"><span class="toc-num">14</span>Merge with Join</a>
|
|
433
|
+
<a class="toc-link" href="#s-flow-for"><span class="toc-num">15</span>Sequential Loop — for</a>
|
|
434
|
+
<a class="toc-link" href="#s-flow-par"><span class="toc-num">16</span>Parallel Loop — par</a>
|
|
435
|
+
<a class="toc-link" href="#s-modules"><span class="toc-num">17</span>Modules</a>
|
|
436
|
+
</div>
|
|
437
|
+
<div class="toc-group">
|
|
438
|
+
<div class="toc-group-label">Advanced & Debug</div>
|
|
439
|
+
<a class="toc-link" href="#s-scope"><span class="toc-num">18</span>scope — Perspective Isolation</a>
|
|
440
|
+
<a class="toc-link" href="#s-actor-system"><span class="toc-num">19</span>@actor Type System</a>
|
|
441
|
+
<a class="toc-link" href="#s-setvariable"><span class="toc-num">20</span>AI Variable Assignment Signal</a>
|
|
442
|
+
<a class="toc-link" href="#s-debug"><span class="toc-num">21</span>Debug Guide</a>
|
|
443
|
+
<a class="toc-link" href="#s-example"><span class="toc-num">22</span>Complete Example</a>
|
|
444
|
+
</div>
|
|
445
|
+
<div class="toc-group">
|
|
446
|
+
<div class="toc-group-label">Developer Reference</div>
|
|
447
|
+
<a class="toc-link" href="#s-blocks"><span class="toc-num">23</span>Prompt Block Collection</a>
|
|
448
|
+
<a class="toc-link" href="#s-session"><span class="toc-num">24</span>Session & Turn Management</a>
|
|
449
|
+
<a class="toc-link" href="#s-storage"><span class="toc-num">25</span>Dialog Storage Rules</a>
|
|
450
|
+
<a class="toc-link" href="#s-db"><span class="toc-num">26</span>Database Schema</a>
|
|
451
|
+
<a class="toc-link" href="#s-engine"><span class="toc-num">27</span>Async Engine Architecture</a>
|
|
452
|
+
<a class="toc-link" href="#s-runtime"><span class="toc-num">28</span>Runtime Integration</a>
|
|
453
|
+
<a class="toc-link" href="#s-devguide"><span class="toc-num">29</span>Tuning & Extension Guide</a>
|
|
454
|
+
<a class="toc-link" href="#s-engineapi"><span class="toc-num">30</span>AsyncEngine API Reference</a>
|
|
455
|
+
</div>
|
|
456
|
+
</nav>
|
|
457
|
+
</aside>
|
|
458
|
+
|
|
459
|
+
<!-- Main -->
|
|
460
|
+
<main id="main">
|
|
461
|
+
<div id="topbar">
|
|
462
|
+
<div class="topbar-path">
|
|
463
|
+
<span>femo</span> / <span>docs</span> / <span style="color:var(--text1)">syntax reference</span>
|
|
464
|
+
</div>
|
|
465
|
+
<div class="topbar-actions">
|
|
466
|
+
<a href="femo.html" class="topbar-btn">← Project Overview</a>
|
|
467
|
+
<a href="https://github.com/Phant0Meow/Femo" class="topbar-btn" target="_blank">GitHub ↗</a>
|
|
468
|
+
</div>
|
|
469
|
+
</div>
|
|
470
|
+
|
|
471
|
+
<div id="content">
|
|
472
|
+
|
|
473
|
+
<!-- ─── 00 Overview ─── -->
|
|
474
|
+
<div class="doc-section" id="sec-overview">
|
|
475
|
+
<span class="section-anchor" id="s-overview"></span>
|
|
476
|
+
<div class="section-header">
|
|
477
|
+
<span class="section-num">00</span>
|
|
478
|
+
<h2 class="section-title">Overview & Design Philosophy</h2>
|
|
479
|
+
<span class="section-badge badge-core">Core</span>
|
|
480
|
+
</div>
|
|
481
|
+
|
|
482
|
+
<p><strong>Femo (Flow Engine for Minds · Work Automata)</strong> is a DSL (Domain-Specific Language) and compiler for orchestrating multi-agent workflows. Its core idea: <em>describe AI collaboration the way you write a screenplay</em>.</p>
|
|
483
|
+
|
|
484
|
+
<div class="callout tip">
|
|
485
|
+
<span class="callout-icon">🖱️</span>
|
|
486
|
+
<div class="callout-body">New users: start with the visual editor at <a href="http://femo.net" target="_blank">femo.net</a>. It supports drag-and-drop flow building — advanced constructs like <code>for</code> and <code>par</code> have visual equivalents too. No code required. Come back here once you want to understand the syntax in depth.</div>
|
|
487
|
+
</div>
|
|
488
|
+
|
|
489
|
+
<div class="callout tip">
|
|
490
|
+
<span class="callout-icon">💡</span>
|
|
491
|
+
<div class="callout-body"><strong>Three core principles</strong> — understand these and you understand Femo:<br>
|
|
492
|
+
① <strong>Scope = Space</strong>: only actors sharing a scope share context — perspective isolation is built-in;<br>
|
|
493
|
+
② <strong>Vars = Flow Control</strong>: variables aren't for passing messages — they drive flow direction;<br>
|
|
494
|
+
③ <strong>Context is not a variable</strong>: LLMs communicate through shared context, not explicit parameters.</div>
|
|
495
|
+
</div>
|
|
496
|
+
|
|
497
|
+
<p>Femo files use the extension <span class="hl">.femo</span> (the <em>s</em> stands for <em>script</em>). The compiler reads a .femo file, parses the script, and drives agent collaboration according to the rules defined within.</p>
|
|
498
|
+
|
|
499
|
+
<div class="callout info">
|
|
500
|
+
<span class="callout-icon">📖</span>
|
|
501
|
+
<div class="callout-body">This document describes Femo v1.0 compiler behavior. Features marked <strong>TODO / Not yet implemented</strong> are noted — please read carefully.</div>
|
|
502
|
+
</div>
|
|
503
|
+
</div>
|
|
504
|
+
|
|
505
|
+
<!-- ─── 01 Structure ─── -->
|
|
506
|
+
<div class="doc-section" id="sec-structure">
|
|
507
|
+
<span class="section-anchor" id="s-structure"></span>
|
|
508
|
+
<div class="section-header">
|
|
509
|
+
<span class="section-num">01</span>
|
|
510
|
+
<h2 class="section-title">File Structure</h2>
|
|
511
|
+
<span class="section-badge badge-core">Core</span>
|
|
512
|
+
</div>
|
|
513
|
+
<p>A .femo script is organized in the following order. All blocks are optional except <span class="hl">mainflow</span>, which is required:</p>
|
|
514
|
+
|
|
515
|
+
<div class="code-block">
|
|
516
|
+
<div class="code-header"><span class="code-lang">femo · overall structure</span><button class="code-copy">copy</button></div>
|
|
517
|
+
<pre><span class="k">meta</span>: <span class="c"># Script metadata</span>
|
|
518
|
+
<span class="k">vars</span>: <span class="c"># Optional · global state variable pool · must be declared before use</span>
|
|
519
|
+
<span class="k">code</span>: <span class="c"># Optional · external Python module imports · required for @func</span>
|
|
520
|
+
<span class="k">actors</span>: <span class="c"># Recommended · role definitions · AI has no persona if omitted</span>
|
|
521
|
+
<span class="k">memory</span>: <span class="c"># Optional · memory retrieval method definitions</span>
|
|
522
|
+
<span class="k">context</span>: <span class="c"># Optional · context extraction method definitions</span>
|
|
523
|
+
<span class="k">action</span> ...: <span class="c"># Required · action definitions · at least one, can be many</span>
|
|
524
|
+
<span class="k">module</span> ...: <span class="c"># Optional · module definitions · can be many</span>
|
|
525
|
+
<span class="k">mainflow</span>: <span class="c"># Required · main flow orchestration</span></pre>
|
|
526
|
+
</div>
|
|
527
|
+
|
|
528
|
+
<div class="callout warn">
|
|
529
|
+
<span class="callout-icon">⚠️</span>
|
|
530
|
+
<div class="callout-body"><strong>Indentation-sensitive</strong>: indentation expresses ownership, similar to Python. <strong>Newline-sensitive</strong>: flow control constructs like <code>fork</code>, <code>for</code>, and <code>par</code> must follow strict indentation and newline rules — the parser will error otherwise.</div>
|
|
531
|
+
</div>
|
|
532
|
+
</div>
|
|
533
|
+
|
|
534
|
+
<!-- ─── 02 Conventions ─── -->
|
|
535
|
+
<div class="doc-section" id="sec-conventions">
|
|
536
|
+
<span class="section-anchor" id="s-conventions"></span>
|
|
537
|
+
<div class="section-header">
|
|
538
|
+
<span class="section-num">02</span>
|
|
539
|
+
<h2 class="section-title">Conventions & Symbol Reference</h2>
|
|
540
|
+
<span class="section-badge badge-core">Core</span>
|
|
541
|
+
</div>
|
|
542
|
+
|
|
543
|
+
<ul>
|
|
544
|
+
<li><strong>Case-sensitive</strong>: variable names and action names are case-sensitive</li>
|
|
545
|
+
<li><strong>Comments</strong>: use <span class="hl">#</span> or <span class="hl">//</span> inline</li>
|
|
546
|
+
<li><strong>@ symbol</strong>: actor entity names always carry <span class="hl">@</span> — in definitions, references, and parameter passing</li>
|
|
547
|
+
<li><strong>File paths</strong>: must use <span class="hl">file:"path/to/file"</span> format; bare text is treated as a string literal</li>
|
|
548
|
+
<li><strong>Multi-line text</strong>: use <span class="hl">|</span> followed by an indented newline for multi-line string literals</li>
|
|
549
|
+
</ul>
|
|
550
|
+
|
|
551
|
+
<h3 class="sub">Core Symbols</h3>
|
|
552
|
+
<div class="table-wrap">
|
|
553
|
+
<table>
|
|
554
|
+
<tr><th>Symbol</th><th>Meaning</th><th>Example</th></tr>
|
|
555
|
+
<tr><td><code>action</code></td><td>Define an action (like Python's <code>def</code>)</td><td><code>action wolf_kill @ai(@wolf):</code></td></tr>
|
|
556
|
+
<tr><td><code>@</code></td><td>Reference / point to an Actor entity</td><td><code>@wolfClaire</code>, <code>@ellis.type</code></td></tr>
|
|
557
|
+
<tr><td><code>[]</code></td><td>Flow node position marker</td><td><code>[A]</code>, <code>[START]</code>, <code>[END]</code></td></tr>
|
|
558
|
+
<tr><td><code>{}</code></td><td>Variable interpolation (prompt f-string)</td><td><code>alive_players</code></td></tr>
|
|
559
|
+
<tr><td><code><<>></code></td><td>AI output assignment signal</td><td><code>SET VARIABLE: <<@VOTE = @player3>></code></td></tr>
|
|
560
|
+
<tr><td><code>&</code></td><td>Reference a Module (black-box)</td><td><code>&CoderSandbox(arg)</code></td></tr>
|
|
561
|
+
<tr><td><code>-></code></td><td>Flow connection direction</td><td><code>[A] -> [B]</code></td></tr>
|
|
562
|
+
</table>
|
|
563
|
+
</div>
|
|
564
|
+
</div>
|
|
565
|
+
|
|
566
|
+
<!-- ─── 03 meta ─── -->
|
|
567
|
+
<div class="doc-section" id="sec-meta">
|
|
568
|
+
<span class="section-anchor" id="s-meta"></span>
|
|
569
|
+
<div class="section-header">
|
|
570
|
+
<span class="section-num">03</span>
|
|
571
|
+
<h2 class="section-title">meta — Script Metadata</h2>
|
|
572
|
+
<span class="section-badge badge-core">Core</span>
|
|
573
|
+
</div>
|
|
574
|
+
<p>Defines the script's basic properties and runtime environment.</p>
|
|
575
|
+
<div class="code-block">
|
|
576
|
+
<div class="code-header"><span class="code-lang">femo</span><button class="code-copy">copy</button></div>
|
|
577
|
+
<pre><span class="k">meta</span>:
|
|
578
|
+
<span class="f">name</span> = <span class="s">"My Werewolf Game"</span>
|
|
579
|
+
<span class="f">version</span> = <span class="v">1.0</span>
|
|
580
|
+
<span class="f">owner</span> = [<span class="v">1</span>, <span class="v">2</span>]
|
|
581
|
+
<span class="f">database</span> = file:<span class="s">"werewolf.db"</span>
|
|
582
|
+
<span class="f">session</span> = <span class="k">new</span> <span class="c"># or specify an integer session_id</span>
|
|
583
|
+
<span class="f">system_safety</span> = <span class="v">|</span>
|
|
584
|
+
No database deletion. No harmful content generation.
|
|
585
|
+
<span class="f">output_style</span> = <span class="s">"Keep replies concise and professional."</span></pre>
|
|
586
|
+
</div>
|
|
587
|
+
|
|
588
|
+
<div class="table-wrap">
|
|
589
|
+
<table>
|
|
590
|
+
<tr><th>Field</th><th>Type</th><th>Description</th></tr>
|
|
591
|
+
<tr><td><code>name</code></td><td>text</td><td>Script name, written to the database when a new session is created</td></tr>
|
|
592
|
+
<tr><td><code>owner</code></td><td>integer array</td><td>Owner user_ids; the compiler auto-injects user info into context</td></tr>
|
|
593
|
+
<tr><td><code>database</code></td><td>file path</td><td>SQLite database path; defaults to <code>./chronica.wor</code> if not specified</td></tr>
|
|
594
|
+
<tr><td><code>session</code></td><td>integer / <code>new</code></td><td><code>new</code> creates a new session automatically; a number loads an existing one; <code>17/new</code> is also valid</td></tr>
|
|
595
|
+
<tr><td><code>system_safety</code></td><td>text / file path</td><td>Safety policy injected into all actors' context automatically</td></tr>
|
|
596
|
+
<tr><td><code>output_style</code></td><td>text / file path</td><td>Output quality guidelines, auto-injected into context</td></tr>
|
|
597
|
+
</table>
|
|
598
|
+
</div>
|
|
599
|
+
|
|
600
|
+
<div class="callout info">
|
|
601
|
+
<span class="callout-icon">ℹ️</span>
|
|
602
|
+
<div class="callout-body"><code>session = 17 / new</code> means: load session 17 if it already exists; if you happen to be creating it fresh and it becomes 17, create it automatically; otherwise the backend will ask whether to proceed.</div>
|
|
603
|
+
</div>
|
|
604
|
+
</div>
|
|
605
|
+
|
|
606
|
+
<!-- ─── 04 vars ─── -->
|
|
607
|
+
<div class="doc-section" id="sec-vars">
|
|
608
|
+
<span class="section-anchor" id="s-vars"></span>
|
|
609
|
+
<div class="section-header">
|
|
610
|
+
<span class="section-num">04</span>
|
|
611
|
+
<h2 class="section-title">vars — Global Variable Pool</h2>
|
|
612
|
+
<span class="section-badge badge-core">Core</span>
|
|
613
|
+
</div>
|
|
614
|
+
<p>All global state variables are declared here. <em>Variables must be declared before use</em> — directly assigning an undeclared variable causes an error.</p>
|
|
615
|
+
|
|
616
|
+
<div class="code-block">
|
|
617
|
+
<div class="code-header"><span class="code-lang">femo</span><button class="code-copy">copy</button></div>
|
|
618
|
+
<pre><span class="k">vars</span>:
|
|
619
|
+
turn_count = <span class="v">1</span>
|
|
620
|
+
game_over = <span class="v">false</span>
|
|
621
|
+
alive_players = [<span class="at">@seer</span>, <span class="at">@wolf</span>] <span class="c"># @actor array</span>
|
|
622
|
+
agent_locations = {<span class="at">@ellis</span>: <span class="s">"bedroom"</span>, <span class="at">@bob</span>: <span class="s">"park"</span>} <span class="c"># dict</span>
|
|
623
|
+
<span class="at">@speaker</span> = <span class="s">""</span> <span class="c"># @actor-type variable, empty value is ""</span>
|
|
624
|
+
hp = {<span class="at">@wolf</span>: <span class="v">100</span>, <span class="at">@seer</span>: <span class="v">100</span>}</pre>
|
|
625
|
+
</div>
|
|
626
|
+
|
|
627
|
+
<h3 class="sub">Key Points</h3>
|
|
628
|
+
<ul>
|
|
629
|
+
<li><strong>@actor-type variables</strong>: variable name must start with <span class="hl">@</span>, e.g. <code>@speaker</code>, to be recognized as an actor type</li>
|
|
630
|
+
<li><strong>@actor dual-perspective access</strong>: <code>hp.@wolf</code> and <code>@wolf.hp</code> are fully equivalent (see section 19)</li>
|
|
631
|
+
<li><strong>Dictionary default</strong>: using <code>{dict[key]}</code> in a prompt where the key doesn't exist resolves to an empty string — no error</li>
|
|
632
|
+
</ul>
|
|
633
|
+
</div>
|
|
634
|
+
|
|
635
|
+
<!-- ─── 05 actors ─── -->
|
|
636
|
+
<div class="doc-section" id="sec-actors">
|
|
637
|
+
<span class="section-anchor" id="s-actors"></span>
|
|
638
|
+
<div class="section-header">
|
|
639
|
+
<span class="section-num">05</span>
|
|
640
|
+
<h2 class="section-title">actors — Role Definitions</h2>
|
|
641
|
+
<span class="section-badge badge-core">Core</span>
|
|
642
|
+
</div>
|
|
643
|
+
<p>Uses a strong-typed declaration style: <span class="hl">type @name = attributes</span>.</p>
|
|
644
|
+
|
|
645
|
+
<div class="code-block">
|
|
646
|
+
<div class="code-header"><span class="code-lang">femo</span><button class="code-copy">copy</button></div>
|
|
647
|
+
<pre><span class="k">actors</span>:
|
|
648
|
+
ai <span class="at">@hostgod</span> = soul:<span class="v">0</span>, source:<span class="v">deepseek</span>
|
|
649
|
+
ai <span class="at">@wolf</span> = soul:<span class="v">1</span>, source:<span class="v">glm5.1</span>, tools:[<span class="v">deep_think</span>]
|
|
650
|
+
ai <span class="at">@seer</span> = soul:<span class="v">2</span>, source:<span class="v">glm5</span>
|
|
651
|
+
human <span class="at">@player</span> = soul:<span class="v">9</span>, source:<span class="v">0</span> <span class="c"># source:0 = human user without admin perspective</span></pre>
|
|
652
|
+
</div>
|
|
653
|
+
|
|
654
|
+
<div class="table-wrap">
|
|
655
|
+
<table>
|
|
656
|
+
<tr><th>Field</th><th>Description</th></tr>
|
|
657
|
+
<tr><td><code>soul:ID</code></td><td>Unique soul ID, mapped to the database <code>souls</code> table; the compiler extracts the system prompt automatically</td></tr>
|
|
658
|
+
<tr><td><code>source:model</code></td><td>For AI: the model name; for humans: the numeric user ID; omit for random assignment</td></tr>
|
|
659
|
+
<tr><td><code>source:0</code></td><td>Special value: a human user without admin perspective — only sees through the soul's viewpoint (ideal for Werewolf-style players)</td></tr>
|
|
660
|
+
<tr><td><code>tools:[...]</code></td><td>Attached tool list, e.g. <code>web_search</code>, <code>deep_think</code></td></tr>
|
|
661
|
+
</table>
|
|
662
|
+
</div>
|
|
663
|
+
|
|
664
|
+
<div class="callout danger">
|
|
665
|
+
<span class="callout-icon">🚫</span>
|
|
666
|
+
<div class="callout-body"><strong>Actor entity names always carry @</strong> and must never be stripped: in definitions <code>ai @ellis = ...</code>, in references <code>@ai(@ellis)</code>, in variable passing <code>@speaker = @ellis</code>. The <code>@</code> is part of the variable name — without it the actor type cannot be recognized.</div>
|
|
667
|
+
</div>
|
|
668
|
+
</div>
|
|
669
|
+
|
|
670
|
+
<!-- ─── 06 code ─── -->
|
|
671
|
+
<div class="doc-section" id="sec-code">
|
|
672
|
+
<span class="section-anchor" id="s-code"></span>
|
|
673
|
+
<div class="section-header">
|
|
674
|
+
<span class="section-num">06</span>
|
|
675
|
+
<h2 class="section-title">code — External Python Modules</h2>
|
|
676
|
+
<span class="section-badge badge-core">Core</span>
|
|
677
|
+
</div>
|
|
678
|
+
<p>Import Python files for use by <span class="hl">@func</span> and <span class="hl">resolve</span>. Paths must use the <span class="hl">file:"..."</span> format. <strong>Absolute paths are preferred</strong>; a relative path like <span class="hl">file:"wait.py"</span> resolves to <span class="hl">/Users/{user_name}/Femo/func_code/wait.py</span>.</p>
|
|
679
|
+
|
|
680
|
+
<div class="code-block">
|
|
681
|
+
<div class="code-header"><span class="code-lang">femo</span><button class="code-copy">copy</button></div>
|
|
682
|
+
<pre><span class="k">code</span>:
|
|
683
|
+
game_logic = file:<span class="s">"utils/game.py"</span>
|
|
684
|
+
dev_ops = file:<span class="s">"utils/deploy.py"</span>
|
|
685
|
+
memfile = file:<span class="s">"femoBridges/MemoryExample.py"</span></pre>
|
|
686
|
+
</div>
|
|
687
|
+
|
|
688
|
+
<div class="callout warn">
|
|
689
|
+
<span class="callout-icon">⚠️</span>
|
|
690
|
+
<div class="callout-body">The following are <strong>reserved keywords</strong> and cannot be used as code aliases: <code>meta</code>, <code>vars</code>, <code>code</code>, <code>actors</code>, <code>action</code>, <code>module</code>, <code>flow</code>, <code>mainflow</code>, <code>memory</code>, <code>context</code></div>
|
|
691
|
+
</div>
|
|
692
|
+
</div>
|
|
693
|
+
|
|
694
|
+
<!-- ─── 07 memory context ─── -->
|
|
695
|
+
<div class="doc-section" id="sec-memory">
|
|
696
|
+
<span class="section-anchor" id="s-memory"></span>
|
|
697
|
+
<div class="section-header">
|
|
698
|
+
<span class="section-num">07</span>
|
|
699
|
+
<h2 class="section-title">memory & context Definitions</h2>
|
|
700
|
+
<span class="section-badge badge-core">Core</span>
|
|
701
|
+
</div>
|
|
702
|
+
<p><strong>memory</strong> and <strong>context</strong> methods define how AI actors receive memory and conversational history. They live at the same level as actions and modules.</p>
|
|
703
|
+
|
|
704
|
+
<div class="code-block">
|
|
705
|
+
<div class="code-header"><span class="code-lang">femo · definition syntax</span><button class="code-copy">copy</button></div>
|
|
706
|
+
<pre><span class="k">memory</span> rag10(memfile.retrieve_example):
|
|
707
|
+
<span class="f">in</span>: prompt, session_id, <span class="at">@actor</span>
|
|
708
|
+
<span class="f">out</span>: memory_text
|
|
709
|
+
|
|
710
|
+
<span class="k">context</span> thisSession(ctxfile.findThisSession):
|
|
711
|
+
<span class="f">in</span>: session, <span class="at">@actor</span>
|
|
712
|
+
<span class="f">out</span>: context_text</pre>
|
|
713
|
+
</div>
|
|
714
|
+
|
|
715
|
+
<h3 class="sub">Reserved in Parameters</h3>
|
|
716
|
+
<div class="table-wrap">
|
|
717
|
+
<table>
|
|
718
|
+
<tr><th>Field</th><th>Value Passed</th></tr>
|
|
719
|
+
<tr><td><code>prompt</code></td><td>The current action's prompt after variable substitution</td></tr>
|
|
720
|
+
<tr><td><code>@actor</code></td><td>The current speaker's actor_info dict (Python-side param name auto-maps to <code>actor_info</code>)</td></tr>
|
|
721
|
+
<tr><td><code>session</code> / <code>session_id</code></td><td>The current session ID</td></tr>
|
|
722
|
+
<tr><td><code>turn</code> / <code>turn_id</code></td><td>The current turn ID</td></tr>
|
|
723
|
+
<tr><td>Any other name</td><td>Fetched from global vars by the same name</td></tr>
|
|
724
|
+
</table>
|
|
725
|
+
</div>
|
|
726
|
+
|
|
727
|
+
<h3 class="sub">Referencing in an Action</h3>
|
|
728
|
+
<div class="code-block">
|
|
729
|
+
<div class="code-header"><span class="code-lang">femo</span><button class="code-copy">copy</button></div>
|
|
730
|
+
<pre><span class="k">action</span> speak <span class="at">@ai</span>(<span class="at">@ellis</span>):
|
|
731
|
+
prompt: <span class="s">"Hello"</span>
|
|
732
|
+
<span class="f">memory</span>: rag10 <span class="c"># omit to use the first memory method, or the built-in default</span>
|
|
733
|
+
<span class="f">context</span>: thisSession <span class="c"># omit to use the first context method, or the built-in default</span></pre>
|
|
734
|
+
</div>
|
|
735
|
+
|
|
736
|
+
<div class="callout info">
|
|
737
|
+
<span class="callout-icon">ℹ️</span>
|
|
738
|
+
<div class="callout-body">If no context method is defined, the FEMO compiler uses a built-in default — it retrieves context from the current session filtered by scope. This is sufficient for most scenarios.</div>
|
|
739
|
+
</div>
|
|
740
|
+
</div>
|
|
741
|
+
|
|
742
|
+
<!-- ─── 08 action ai ─── -->
|
|
743
|
+
<div class="doc-section" id="sec-action-ai">
|
|
744
|
+
<span class="section-anchor" id="s-action-ai"></span>
|
|
745
|
+
<div class="section-header">
|
|
746
|
+
<span class="section-num">08</span>
|
|
747
|
+
<h2 class="section-title">AI Action — @ai</h2>
|
|
748
|
+
<span class="section-badge badge-core">Core</span>
|
|
749
|
+
</div>
|
|
750
|
+
<p>The most common action type. Calls an LLM to complete one round of dialogue.</p>
|
|
751
|
+
|
|
752
|
+
<div class="code-block">
|
|
753
|
+
<div class="code-header"><span class="code-lang">femo · full field reference</span><button class="code-copy">copy</button></div>
|
|
754
|
+
<pre><span class="k">action</span> wolf_kill <span class="at">@ai</span>(<span class="at">@wolf</span>):
|
|
755
|
+
<span class="f">prompt</span>: <span class="v">|</span>
|
|
756
|
+
It is night {turn_count}. Surviving players: {alive_players}.
|
|
757
|
+
You are the werewolf. Choose a target to eliminate.
|
|
758
|
+
After reasoning, output: SET VARIABLE: <<@KILL = @player_name>>
|
|
759
|
+
<span class="f">scope</span>: [<span class="at">@hostgod</span>, <span class="at">@wolf</span>]
|
|
760
|
+
<span class="f">out</span>: wolf_target(string, <span class="s">"kill target"</span>)
|
|
761
|
+
<span class="f">resolve</span>: game_logic.resolve_target(@KILL, alive_players)
|
|
762
|
+
<span class="f">max_retries</span>: <span class="v">3</span>
|
|
763
|
+
<span class="f">fallback</span>: host_emergency
|
|
764
|
+
<span class="f">context</span>: thisSession
|
|
765
|
+
<span class="f">memory</span>: rag10</pre>
|
|
766
|
+
</div>
|
|
767
|
+
|
|
768
|
+
<h3 class="sub">Field Reference</h3>
|
|
769
|
+
|
|
770
|
+
<h4 class="sub2">prompt</h4>
|
|
771
|
+
<p>Supports <span class="hl">{var}</span> f-string interpolation. By default all global variables are substituted; if an <span class="hl">in:</span> field is present, only the listed variables are substituted (useful for controlling information exposure).</p>
|
|
772
|
+
<div class="code-block">
|
|
773
|
+
<div class="code-header"><span class="code-lang">femo · in field example</span><button class="code-copy">copy</button></div>
|
|
774
|
+
<pre><span class="k">action</span> coder_act <span class="at">@ai</span>(<span class="at">@coder</span>):
|
|
775
|
+
<span class="f">in</span>: my_task = task_list[<span class="at">@coder</span>] <span class="c"># left=name used in prompt, right=global variable expression</span>
|
|
776
|
+
<span class="f">prompt</span>: <span class="s">"Your task is: {my_task}"</span> <span class="c"># {other_var} won't be replaced — preserved as-is</span></pre>
|
|
777
|
+
</div>
|
|
778
|
+
|
|
779
|
+
<h4 class="sub2">scope</h4>
|
|
780
|
+
<p>Defines which actors can see this round of dialogue. Supports dynamic variables, e.g. <span class="hl">scope: playersInPark</span>. See section 18 for details.</p>
|
|
781
|
+
|
|
782
|
+
<h4 class="sub2">out — AI Output Variable</h4>
|
|
783
|
+
<p>Declares which variable the AI must output. Format: <span class="hl">variable_name(type, "label")</span>. The AI must include <code>SET VARIABLE: <<var_name = value>></code> in its reply. The variable must already be declared in <code>vars</code>.</p>
|
|
784
|
+
<p>Writing to a dictionary key is also supported: <span class="hl">vote_results.@voter(string, "")</span> stores the value into the specified key of the dict.</p>
|
|
785
|
+
|
|
786
|
+
<h4 class="sub2">resolve — Validation Function (optional)</h4>
|
|
787
|
+
<p>Used when complex validation or non-standard AI output format handling is needed.</p>
|
|
788
|
+
<div class="code-block">
|
|
789
|
+
<div class="code-header"><span class="code-lang">femo + python · resolve example</span><button class="code-copy">copy</button></div>
|
|
790
|
+
<pre><span class="c"># in .femo</span>
|
|
791
|
+
<span class="f">resolve</span>: game_logic.resolve_target(@KILL, alive_players, SET_VARIABLE)
|
|
792
|
+
<span class="c"># including SET_VARIABLE causes the compiler to pass in any failed-parse assignment list</span>
|
|
793
|
+
|
|
794
|
+
<span class="c"># Python (utils/game.py)</span>
|
|
795
|
+
def resolve_target(@KILL=None, alive_players=None, SET_VARIABLE=None, **kwargs):
|
|
796
|
+
if @KILL and @KILL in alive_players:
|
|
797
|
+
return [(True, False, <span class="s">""</span>)] <span class="c"># (is_success, show_to_ai, feedback)</span>
|
|
798
|
+
if SET_VARIABLE: <span class="c"># built-in parse failed — handle manually</span>
|
|
799
|
+
import re
|
|
800
|
+
for item in SET_VARIABLE:
|
|
801
|
+
m = re.match(r<span class="s">'@KILL\s*=\s*@(\w+)'</span>, item)
|
|
802
|
+
if m and f<span class="s">"@{m.group(1)}"</span> in alive_players:
|
|
803
|
+
return [(True, False, <span class="s">""</span>)]
|
|
804
|
+
return [(False, True, <span class="s">"Target not in alive players. Please choose again."</span>)]</pre>
|
|
805
|
+
</div>
|
|
806
|
+
|
|
807
|
+
<div class="callout warn">
|
|
808
|
+
<span class="callout-icon">⚠️</span>
|
|
809
|
+
<div class="callout-body"><strong>Current version limitation</strong>: <code>max_retries</code> and <code>fallback</code> fields are reserved but auto-retry is not yet implemented. The <code>show_to_ai</code> and <code>feedback</code> return values in <code>resolve</code> are also not yet active.</div>
|
|
810
|
+
</div>
|
|
811
|
+
|
|
812
|
+
<h4 class="sub2">Dynamic @actor_expr</h4>
|
|
813
|
+
<div class="callout info">
|
|
814
|
+
<span class="callout-icon">ℹ️</span>
|
|
815
|
+
<div class="callout-body">When using a dynamic variable in the action's parentheses (e.g. <code>@ai(@speaker)</code>), the <code>for</code>/<code>par</code> loop variable name must exactly match the variable name in the parentheses — otherwise the engine errors immediately.</div>
|
|
816
|
+
</div>
|
|
817
|
+
</div>
|
|
818
|
+
|
|
819
|
+
<!-- ─── 09 human action ─── -->
|
|
820
|
+
<div class="doc-section" id="sec-action-human">
|
|
821
|
+
<span class="section-anchor" id="s-action-human"></span>
|
|
822
|
+
<div class="section-header">
|
|
823
|
+
<span class="section-num">09</span>
|
|
824
|
+
<h2 class="section-title">Human Action — @human</h2>
|
|
825
|
+
<span class="section-badge badge-core">Core</span>
|
|
826
|
+
</div>
|
|
827
|
+
<p>Syntax is largely identical to @ai. Used to incorporate human player input into the workflow.</p>
|
|
828
|
+
|
|
829
|
+
<div class="code-block">
|
|
830
|
+
<div class="code-header"><span class="code-lang">femo</span><button class="code-copy">copy</button></div>
|
|
831
|
+
<pre><span class="k">action</span> human_vote <span class="at">@human</span>(<span class="at">@player</span>):
|
|
832
|
+
<span class="f">prompt</span>: <span class="s">Cast your vote:</span>
|
|
833
|
+
<span class="f">scope</span>: [<span class="at">@hostgod</span>] + alive_players
|
|
834
|
+
<span class="f">out</span>: vote_target(dropdown, choices=alive_players, label=<span class="s">"Vote"</span>)
|
|
835
|
+
<span class="f">resolve</span>: game_logic.resolve_human_vote
|
|
836
|
+
|
|
837
|
+
<span class="c"># Let a human play as a specific AI role, inheriting that role's scope:</span>
|
|
838
|
+
<span class="k">action</span> seer_act <span class="at">@human</span>(<span class="at">@player</span>) as (<span class="at">@seer</span>):
|
|
839
|
+
<span class="f">prompt</span>: <span class="s">You are now the Seer. Who do you want to inspect?</span>
|
|
840
|
+
<span class="f">scope</span>: [<span class="at">@seer</span>, <span class="at">@hostgod</span>]</pre>
|
|
841
|
+
</div>
|
|
842
|
+
|
|
843
|
+
<ul>
|
|
844
|
+
<li>The <code>out</code> type <strong>dropdown</strong> maps to a dropdown UI component in the frontend</li>
|
|
845
|
+
<li>Human actions support context (same syntax as AI actions) but not memory</li>
|
|
846
|
+
<li><strong>as (@role)</strong>: allows the human player to enter a specific AI role's private perspective</li>
|
|
847
|
+
</ul>
|
|
848
|
+
</div>
|
|
849
|
+
|
|
850
|
+
<!-- ─── 10 assign ─── -->
|
|
851
|
+
<div class="doc-section" id="sec-action-assign">
|
|
852
|
+
<span class="section-anchor" id="s-action-assign"></span>
|
|
853
|
+
<div class="section-header">
|
|
854
|
+
<span class="section-num">10</span>
|
|
855
|
+
<h2 class="section-title">Assignment Action — @assign</h2>
|
|
856
|
+
<span class="section-badge badge-core">Core</span>
|
|
857
|
+
</div>
|
|
858
|
+
<p>Lightweight assignment — <em>does not call an LLM</em>, directly modifies global variables.</p>
|
|
859
|
+
|
|
860
|
+
<div class="code-block">
|
|
861
|
+
<div class="code-header"><span class="code-lang">femo · supported operations</span><button class="code-copy">copy</button></div>
|
|
862
|
+
<pre><span class="k">action</span> next_turn <span class="at">@assign</span>:
|
|
863
|
+
<span class="f">out</span>: day_count <span class="v">+=</span> <span class="v">1</span>
|
|
864
|
+
|
|
865
|
+
<span class="k">action</span> reset_scene <span class="at">@assign</span>:
|
|
866
|
+
<span class="f">out</span>: current_scene <span class="v">=</span> <span class="s">"tavern"</span>, time <span class="v">=</span> <span class="v">sunset</span> <span class="c"># multiple assignments, comma-separated</span>
|
|
867
|
+
|
|
868
|
+
<span class="k">action</span> update_park <span class="at">@assign</span>:
|
|
869
|
+
<span class="f">out</span>: playerInPark <span class="v">= add(</span><span class="at">@Alice</span><span class="v">)</span>
|
|
870
|
+
playerInMarket <span class="v">= remove(</span><span class="at">@Alice</span><span class="v">)</span> <span class="c"># multi-line out is supported</span></pre>
|
|
871
|
+
</div>
|
|
872
|
+
|
|
873
|
+
<div class="table-wrap">
|
|
874
|
+
<table>
|
|
875
|
+
<tr><th>Operation</th><th>Meaning</th></tr>
|
|
876
|
+
<tr><td><code>= value</code></td><td>Direct assignment</td></tr>
|
|
877
|
+
<tr><td><code>+= N</code></td><td>Add N</td></tr>
|
|
878
|
+
<tr><td><code>-= N</code></td><td>Subtract N</td></tr>
|
|
879
|
+
<tr><td><code>= add(element)</code></td><td>Append element to list</td></tr>
|
|
880
|
+
<tr><td><code>= remove(element)</code></td><td>Remove element from list</td></tr>
|
|
881
|
+
</table>
|
|
882
|
+
</div>
|
|
883
|
+
</div>
|
|
884
|
+
|
|
885
|
+
<!-- ─── 11 func ─── -->
|
|
886
|
+
<div class="doc-section" id="sec-action-func">
|
|
887
|
+
<span class="section-anchor" id="s-action-func"></span>
|
|
888
|
+
<div class="section-header">
|
|
889
|
+
<span class="section-num">11</span>
|
|
890
|
+
<h2 class="section-title">Python Function Call — @func</h2>
|
|
891
|
+
<span class="section-badge badge-core">Core</span>
|
|
892
|
+
</div>
|
|
893
|
+
<p>Calls a Python function declared in the <span class="hl">code:</span> block to handle complex logic.</p>
|
|
894
|
+
|
|
895
|
+
<div class="code-block">
|
|
896
|
+
<div class="code-header"><span class="code-lang">femo</span><button class="code-copy">copy</button></div>
|
|
897
|
+
<pre><span class="k">action</span> resolve_night <span class="at">@func</span>(my_utils.resolve_night):
|
|
898
|
+
<span class="f">in</span>:
|
|
899
|
+
kill_target = wolf_target <span class="c"># left=Python param name, right=FEMO variable expression</span>
|
|
900
|
+
save = witch_save_target
|
|
901
|
+
<span class="f">out</span>: dead_tonight, alive_players</pre>
|
|
902
|
+
</div>
|
|
903
|
+
|
|
904
|
+
<h3 class="sub">in Parameter Rules</h3>
|
|
905
|
+
<ul>
|
|
906
|
+
<li><strong>Explicit mode</strong> (with <code>in:</code>): strictly passes declared params, format <code>param_name = variable_expression</code></li>
|
|
907
|
+
<li><strong>Auto-inference mode</strong> (no <code>in:</code>): matches Python function signature against vars by name</li>
|
|
908
|
+
</ul>
|
|
909
|
+
|
|
910
|
+
<h3 class="sub">out Receiving Rules</h3>
|
|
911
|
+
<div class="table-wrap">
|
|
912
|
+
<table>
|
|
913
|
+
<tr><th>Function Return Type</th><th>out Behavior</th></tr>
|
|
914
|
+
<tr><td>Returns a <strong>dict</strong></td><td>Matches by key to variable names in <code>out</code> — keys must exactly match</td></tr>
|
|
915
|
+
<tr><td>Returns a <strong>single value</strong></td><td>When <code>out</code> declares exactly one variable, assigned directly</td></tr>
|
|
916
|
+
<tr><td><code>out: dict.key</code> form</td><td>Function returns just the final value; the compiler handles writing it to the specified dict key</td></tr>
|
|
917
|
+
</table>
|
|
918
|
+
</div>
|
|
919
|
+
|
|
920
|
+
<h3 class="sub">Passing @actor Variables to Python</h3>
|
|
921
|
+
<p>When an <code>in</code> variable is an @actor type, the engine automatically packages it as a dict for Python:</p>
|
|
922
|
+
<div class="code-block">
|
|
923
|
+
<div class="code-header"><span class="code-lang">python · received actor dict</span><button class="code-copy">copy</button></div>
|
|
924
|
+
<pre>{
|
|
925
|
+
<span class="s">"type"</span>: <span class="s">"ai"</span>,
|
|
926
|
+
<span class="s">"name"</span>: <span class="s">"@ellis"</span>,
|
|
927
|
+
<span class="s">"soul"</span>: <span class="v">3</span>,
|
|
928
|
+
<span class="s">"hp"</span>: <span class="v">100</span>, <span class="c"># from the hp dict in vars</span>
|
|
929
|
+
<span class="s">"location"</span>: <span class="s">"tavern"</span> <span class="c"># from the location dict in vars</span>
|
|
930
|
+
}</pre>
|
|
931
|
+
</div>
|
|
932
|
+
|
|
933
|
+
<div class="callout warn">
|
|
934
|
+
<span class="callout-icon">⚠️</span>
|
|
935
|
+
<div class="callout-body">Common mistake: when using <code>out: dict.key</code>, the function should return only the final value — don't build the dict yourself. When returning a dict, all keys must exactly match the declared out variable names — extra or missing keys will error.</div>
|
|
936
|
+
</div>
|
|
937
|
+
</div>
|
|
938
|
+
|
|
939
|
+
<!-- ─── 12 Flow Basic ─── -->
|
|
940
|
+
<div class="doc-section" id="sec-flow-basic">
|
|
941
|
+
<span class="section-anchor" id="s-flow-basic"></span>
|
|
942
|
+
<div class="section-header">
|
|
943
|
+
<span class="section-num">12</span>
|
|
944
|
+
<h2 class="section-title">Basic Chain Flow</h2>
|
|
945
|
+
<span class="section-badge badge-flow">Flow</span>
|
|
946
|
+
</div>
|
|
947
|
+
<p>Flow chains Nodes (position markers) together. <span class="hl">[START]</span> and <span class="hl">[END]</span> are reserved keywords and must exist in <code>mainflow</code>.</p>
|
|
948
|
+
|
|
949
|
+
<div class="callout info">
|
|
950
|
+
<span class="callout-icon">💡</span>
|
|
951
|
+
<div class="callout-body"><strong>Key distinction</strong>: Action = behavior (what to do, has no position); Node = a position container (holds an action or module); Flow = a directed graph that chains Nodes together.<br><br>Reference an Action without prefix; reference a Module with the <code>&</code> prefix.</div>
|
|
952
|
+
</div>
|
|
953
|
+
|
|
954
|
+
<div class="code-block">
|
|
955
|
+
<div class="code-header"><span class="code-lang">femo · sequential chain</span><button class="code-copy">copy</button></div>
|
|
956
|
+
<pre><span class="p">[START]</span> <span class="p">-></span> action0 <span class="p">-></span> <span class="p">[B]</span>:action1 <span class="p">-></span> &module1 <span class="p">-></span> <span class="p">[END]</span>
|
|
957
|
+
|
|
958
|
+
<span class="c"># Split across multiple lines when it gets long — connect head and tail nodes:</span>
|
|
959
|
+
<span class="p">[START]</span> <span class="p">-></span> wolf_discuss <span class="p">-></span> seer_check <span class="p">-></span> <span class="p">[A]</span>:tell_seer
|
|
960
|
+
<span class="p">[A]</span> <span class="p">-></span> witch_ask <span class="p">-></span> resolve_night <span class="p">-></span> <span class="p">[END]</span></pre>
|
|
961
|
+
</div>
|
|
962
|
+
|
|
963
|
+
<h3 class="sub">Loops Require Nodes</h3>
|
|
964
|
+
<div class="two-col">
|
|
965
|
+
<div class="code-block">
|
|
966
|
+
<div class="code-header"><span class="code-lang">❌ Not a loop</span></div>
|
|
967
|
+
<pre><span class="c"># This just runs action1 a second time</span>
|
|
968
|
+
action1 <span class="p">-></span> action2 <span class="p">-></span> action1</pre>
|
|
969
|
+
</div>
|
|
970
|
+
<div class="code-block">
|
|
971
|
+
<div class="code-header"><span class="code-lang">✅ A real loop</span></div>
|
|
972
|
+
<pre><span class="c"># Returns to [A]'s position and continues from there</span>
|
|
973
|
+
<span class="p">[A]</span>:action1 <span class="p">-></span> action2 <span class="p">-></span> <span class="p">[A]</span></pre>
|
|
974
|
+
</div>
|
|
975
|
+
</div>
|
|
976
|
+
</div>
|
|
977
|
+
|
|
978
|
+
<!-- ─── 13 fork ─── -->
|
|
979
|
+
<div class="doc-section" id="sec-flow-fork">
|
|
980
|
+
<span class="section-anchor" id="s-flow-fork"></span>
|
|
981
|
+
<div class="section-header">
|
|
982
|
+
<span class="section-num">13</span>
|
|
983
|
+
<h2 class="section-title">Concurrent Fork</h2>
|
|
984
|
+
<span class="section-badge badge-flow">Flow</span>
|
|
985
|
+
</div>
|
|
986
|
+
<p>fork declares concurrent branches at this point. Each branch runs in a new child thread — ideal for calling multiple LLMs simultaneously.</p>
|
|
987
|
+
|
|
988
|
+
<div class="code-block">
|
|
989
|
+
<div class="code-header"><span class="code-lang">femo · two syntaxes</span><button class="code-copy">copy</button></div>
|
|
990
|
+
<pre><span class="c"># Syntax 1: indented branches</span>
|
|
991
|
+
<span class="p">[A]</span> <span class="p">-></span> <span class="p">[B]</span> <span class="p">-></span>
|
|
992
|
+
<span class="k">fork</span>:
|
|
993
|
+
<span class="p">-></span> [visit]
|
|
994
|
+
<span class="p">-></span> [solo]
|
|
995
|
+
|
|
996
|
+
<span class="c"># Syntax 2: multiple same-indent lines (equivalent)</span>
|
|
997
|
+
<span class="p">[C]</span> <span class="p">-></span> [visit]
|
|
998
|
+
<span class="p">[C]</span> <span class="p">-></span> [solo]
|
|
999
|
+
|
|
1000
|
+
<span class="c"># With conditions — if (Python expression, @actor auto-converted to dict)</span>
|
|
1001
|
+
<span class="p">[A]</span> <span class="p">-></span>
|
|
1002
|
+
<span class="k">fork</span>:
|
|
1003
|
+
<span class="p">-></span> if (var == true) <span class="p">-></span> <span class="p">[B]</span>
|
|
1004
|
+
<span class="p">-></span> if (score > 5 and level >= 3) <span class="p">-></span> <span class="p">[C]</span>
|
|
1005
|
+
<span class="p">-></span> if (<span class="at">@Portia</span>.hp == 0) <span class="p">-></span> <span class="p">[D]</span> <span class="c"># @actor expressions work directly</span></pre>
|
|
1006
|
+
</div>
|
|
1007
|
+
|
|
1008
|
+
<div class="callout info">
|
|
1009
|
+
<span class="callout-icon">ℹ️</span>
|
|
1010
|
+
<div class="callout-body">fork only handles <strong>splitting</strong>, not merging. Use <code>join</code> (next section) for merging. Branches without <code>if</code> conditions all launch unconditionally in parallel.</div>
|
|
1011
|
+
</div>
|
|
1012
|
+
|
|
1013
|
+
<div class="callout tip">
|
|
1014
|
+
<span class="callout-icon">💡</span>
|
|
1015
|
+
<div class="callout-body">You can skip <code>fork</code> entirely and use the mermaid-style multi-line arrow notation to describe branches — sometimes it's simpler. The benefit of <code>fork</code>: less typing when there are many branches, and a cleaner structure for debugging.</div>
|
|
1016
|
+
</div>
|
|
1017
|
+
|
|
1018
|
+
<h3 class="sub">Animation: fork concurrent branching</h3>
|
|
1019
|
+
<div class="anim-wrap" id="anim-fork">
|
|
1020
|
+
<canvas id="canvas-fork" width="700" height="220"></canvas>
|
|
1021
|
+
<div class="anim-controls">
|
|
1022
|
+
<button class="anim-btn" onclick="forkAnim.restart()">↺ Replay</button>
|
|
1023
|
+
</div>
|
|
1024
|
+
</div>
|
|
1025
|
+
</div>
|
|
1026
|
+
|
|
1027
|
+
<!-- ─── 14 join ─── -->
|
|
1028
|
+
<div class="doc-section" id="sec-flow-join">
|
|
1029
|
+
<span class="section-anchor" id="s-flow-join"></span>
|
|
1030
|
+
<div class="section-header">
|
|
1031
|
+
<span class="section-num">14</span>
|
|
1032
|
+
<h2 class="section-title">Merge with Join</h2>
|
|
1033
|
+
<span class="section-badge badge-flow">Flow</span>
|
|
1034
|
+
</div>
|
|
1035
|
+
<p>join is defined at the <em>receiving end</em>, declaring "which upstream nodes I'm waiting for."</p>
|
|
1036
|
+
|
|
1037
|
+
<div class="code-block">
|
|
1038
|
+
<div class="code-header"><span class="code-lang">femo</span><button class="code-copy">copy</button></div>
|
|
1039
|
+
<pre><span class="k">join</span>(all):
|
|
1040
|
+
<span class="p">[B]</span> <span class="p">-></span>
|
|
1041
|
+
<span class="p">[C]</span> <span class="p">-></span>
|
|
1042
|
+
to [next_node]
|
|
1043
|
+
|
|
1044
|
+
<span class="c"># join(2): continue once 2 upstream nodes arrive; cancel remaining branches</span>
|
|
1045
|
+
<span class="k">join</span>(<span class="v">2</span>):
|
|
1046
|
+
<span class="p">[D]</span> <span class="p">-></span>
|
|
1047
|
+
<span class="p">[E]</span> <span class="p">-></span>
|
|
1048
|
+
<span class="p">[F]</span> <span class="p">-></span>
|
|
1049
|
+
to [next_node]</pre>
|
|
1050
|
+
</div>
|
|
1051
|
+
|
|
1052
|
+
<ul>
|
|
1053
|
+
<li><span class="hl">join(all)</span>: wait for all declared upstream nodes to arrive</li>
|
|
1054
|
+
<li><span class="hl">join(N)</span>: continue once N upstream nodes arrive; cancel remaining branches (only those from this fork)</li>
|
|
1055
|
+
</ul>
|
|
1056
|
+
|
|
1057
|
+
<h3 class="sub">join and Mermaid-style Syntax Are Equivalent</h3>
|
|
1058
|
+
<div class="code-block">
|
|
1059
|
+
<div class="code-header"><span class="code-lang">femo · two equivalent styles</span><button class="code-copy">copy</button></div>
|
|
1060
|
+
<pre><span class="c"># join style</span>
|
|
1061
|
+
<span class="k">join</span>(all):
|
|
1062
|
+
<span class="p">[B]</span> <span class="p">-></span>
|
|
1063
|
+
<span class="p">[C]</span> <span class="p">-></span>
|
|
1064
|
+
to [next_node]
|
|
1065
|
+
|
|
1066
|
+
<span class="c"># Equivalent mermaid-style</span>
|
|
1067
|
+
<span class="p">[B]</span> <span class="p">-></span> [next_node]
|
|
1068
|
+
<span class="p">[C]</span> <span class="p">-></span> [next_node]</pre>
|
|
1069
|
+
</div>
|
|
1070
|
+
|
|
1071
|
+
<div class="callout tip">
|
|
1072
|
+
<span class="callout-icon">💡</span>
|
|
1073
|
+
<div class="callout-body">You can skip <code>join</code> entirely: pointing multiple branches at the same node in mermaid style naturally merges them — equivalent to <code>join(all)</code>. Only write <code>join(N)</code> when you need the "stop remaining branches after N arrive" behavior.</div>
|
|
1074
|
+
</div>
|
|
1075
|
+
</div>
|
|
1076
|
+
|
|
1077
|
+
<!-- ─── 15 for ─── -->
|
|
1078
|
+
<div class="doc-section" id="sec-flow-for">
|
|
1079
|
+
<span class="section-anchor" id="s-flow-for"></span>
|
|
1080
|
+
<div class="section-header">
|
|
1081
|
+
<span class="section-num">15</span>
|
|
1082
|
+
<h2 class="section-title">Sequential Loop — for</h2>
|
|
1083
|
+
<span class="section-badge badge-flow">Flow</span>
|
|
1084
|
+
</div>
|
|
1085
|
+
|
|
1086
|
+
<p>Iterates over an array, executing the loop body <em>sequentially</em> for each element — equivalent to an unrolled sequential chain. The entire <code>for</code> block is a single unit; the preceding node is written on the same line as the <span class="hl">for</span> keyword.</p>
|
|
1087
|
+
|
|
1088
|
+
<div class="code-block">
|
|
1089
|
+
<div class="code-header"><span class="code-lang">femo · complete for block</span><button class="code-copy">copy</button></div>
|
|
1090
|
+
<pre><span class="c"># Full structure: preceding node on the same line as for</span>
|
|
1091
|
+
<span class="p">[B]</span> <span class="p">-></span> <span class="k">for</span> <span class="at">@speaker</span> in speaker_array:
|
|
1092
|
+
<span class="p">-></span> <span class="p">[C]</span>:speak <span class="p">-></span> <span class="p">[D]</span>:respond <span class="p">-></span>
|
|
1093
|
+
<span class="p">-></span> <span class="p">[END]</span>
|
|
1094
|
+
|
|
1095
|
+
<span class="c"># Loop variable need not be @actor — plain variables work too</span>
|
|
1096
|
+
<span class="p">[A]</span> <span class="p">-></span> <span class="k">for</span> i in [<span class="v">1</span>, <span class="v">2</span>, <span class="v">3</span>]:
|
|
1097
|
+
<span class="p">-></span> tick_action <span class="p">-></span>
|
|
1098
|
+
<span class="p">-></span> <span class="p">[END]</span>
|
|
1099
|
+
|
|
1100
|
+
<span class="c"># for + if: route by type (exit node is optional)</span>
|
|
1101
|
+
<span class="p">[B]</span> <span class="p">-></span> <span class="k">for</span> <span class="at">@player</span> in alive_players:
|
|
1102
|
+
<span class="p">-></span> if (<span class="at">@player</span>.type == <span class="s">"ai"</span>) <span class="p">-></span> ai_speak <span class="p">-></span>
|
|
1103
|
+
<span class="p">-></span> if (<span class="at">@player</span>.type == <span class="s">"human"</span>) <span class="p">-></span> human_speak <span class="p">-></span>
|
|
1104
|
+
<span class="p">-></span> <span class="p">[D]</span></pre>
|
|
1105
|
+
</div>
|
|
1106
|
+
|
|
1107
|
+
<div class="callout info">
|
|
1108
|
+
<span class="callout-icon">💡</span>
|
|
1109
|
+
<div class="callout-body"><strong>Body markers</strong>: inside a loop, mark the first node with a leading <code>-></code> and the last node with a trailing <code>-></code>. The exit node is optional — if provided, flow continues there after the loop ends; if omitted, the branch terminates automatically. Removing these leading/trailing arrows, the loop body syntax is identical to regular flow.</div>
|
|
1110
|
+
</div>
|
|
1111
|
+
<div class="callout danger">
|
|
1112
|
+
<span class="callout-icon">🚫</span>
|
|
1113
|
+
<div class="callout-body">If the loop variable is an @actor type, its name must exactly match the dynamic variable name in the action definition's parentheses — otherwise the engine errors immediately to prevent silently using the wrong actor.</div>
|
|
1114
|
+
</div>
|
|
1115
|
+
|
|
1116
|
+
<h3 class="sub">Animation: for sequential loop</h3>
|
|
1117
|
+
<div class="anim-wrap" id="anim-for">
|
|
1118
|
+
<canvas id="canvas-for" width="700" height="200"></canvas>
|
|
1119
|
+
<div class="anim-controls">
|
|
1120
|
+
<button class="anim-btn" onclick="forAnim.restart()">↺ Replay</button>
|
|
1121
|
+
</div>
|
|
1122
|
+
</div>
|
|
1123
|
+
</div>
|
|
1124
|
+
|
|
1125
|
+
<!-- ─── 16 par ─── -->
|
|
1126
|
+
<div class="doc-section" id="sec-flow-par">
|
|
1127
|
+
<span class="section-anchor" id="s-flow-par"></span>
|
|
1128
|
+
<div class="section-header">
|
|
1129
|
+
<span class="section-num">16</span>
|
|
1130
|
+
<h2 class="section-title">Parallel Loop — par</h2>
|
|
1131
|
+
<span class="section-badge badge-flow">Flow</span>
|
|
1132
|
+
</div>
|
|
1133
|
+
|
|
1134
|
+
<p>A shorthand for fork + join: iterates over an array, executing <em>concurrently</em> for each element. Dramatically speeds up parallel LLM calls. The preceding node is written on the same line as the <span class="hl">par</span> keyword.</p>
|
|
1135
|
+
|
|
1136
|
+
<div class="code-block">
|
|
1137
|
+
<div class="code-header"><span class="code-lang">femo · par examples</span><button class="code-copy">copy</button></div>
|
|
1138
|
+
<pre><span class="c"># Example 1: preceding node on same line, concurrent module calls</span>
|
|
1139
|
+
<span class="p">[A]</span> <span class="p">-></span> <span class="k">par</span> <span class="at">@coder</span> in coders:
|
|
1140
|
+
<span class="p">-></span> &CoderSandbox(<span class="at">@coder</span>, task_list[<span class="at">@coder</span>]) <span class="p">-></span>
|
|
1141
|
+
<span class="p">-></span> <span class="p">[D]</span>
|
|
1142
|
+
|
|
1143
|
+
<span class="c"># Example 2: each branch executes multiple steps concurrently</span>
|
|
1144
|
+
<span class="p">[before]</span> <span class="p">-></span> <span class="k">par</span> <span class="at">@coder</span> in workers:
|
|
1145
|
+
<span class="p">-></span> <span class="p">[A]</span>:writecode <span class="p">-></span> <span class="p">[B]</span>:trycode <span class="p">-></span>
|
|
1146
|
+
<span class="p">-></span> <span class="p">[D]</span>
|
|
1147
|
+
|
|
1148
|
+
<span class="c"># Variable need not be @actor</span>
|
|
1149
|
+
<span class="p">[A]</span> <span class="p">-></span> <span class="k">par</span> i in [<span class="v">1</span>, <span class="v">2</span>, <span class="v">3</span>]:
|
|
1150
|
+
<span class="p">-></span> tick_action <span class="p">-></span>
|
|
1151
|
+
<span class="p">-></span> <span class="p">[END]</span>
|
|
1152
|
+
|
|
1153
|
+
<span class="c"># Exit node is optional — branches terminate automatically when done</span>
|
|
1154
|
+
<span class="p">[VOTE]</span> <span class="p">-></span> <span class="k">par</span> <span class="at">@player</span> in alive_players:
|
|
1155
|
+
<span class="p">-></span> cast_vote <span class="p">-></span>
|
|
1156
|
+
<span class="c"># No exit node — each branch stops after finishing</span></pre>
|
|
1157
|
+
</div>
|
|
1158
|
+
|
|
1159
|
+
<ul>
|
|
1160
|
+
<li>Multiple nodes inside a branch run sequentially; branches run concurrently with each other</li>
|
|
1161
|
+
<li>The parallel variable is branch-local — different values per branch, no interference; referenced directly in actions without explicit passing</li>
|
|
1162
|
+
<li>Body markers are the same as <code>for</code>: leading <code>-></code> marks the first node, trailing <code>-></code> marks the last</li>
|
|
1163
|
+
<li>Exit node is optional — if present, all branches converge there; if absent, each branch terminates independently</li>
|
|
1164
|
+
<li>The parallel variable need not be @actor — <code>par i in [1,2,3]:</code> is fully valid</li>
|
|
1165
|
+
<li>If the parallel variable is an @actor type, its name must exactly match the action definition's dynamic variable name — otherwise the engine errors immediately</li>
|
|
1166
|
+
</ul>
|
|
1167
|
+
|
|
1168
|
+
<h3 class="sub">Animation: par concurrent execution</h3>
|
|
1169
|
+
<div class="anim-wrap" id="anim-par">
|
|
1170
|
+
<canvas id="canvas-par" width="700" height="260"></canvas>
|
|
1171
|
+
<div class="anim-controls">
|
|
1172
|
+
<button class="anim-btn" onclick="parAnim.restart()">↺ Replay</button>
|
|
1173
|
+
</div>
|
|
1174
|
+
</div>
|
|
1175
|
+
</div>
|
|
1176
|
+
|
|
1177
|
+
<!-- ─── 17 modules ─── -->
|
|
1178
|
+
<div class="doc-section" id="sec-modules">
|
|
1179
|
+
<span class="section-anchor" id="s-modules"></span>
|
|
1180
|
+
<div class="section-header">
|
|
1181
|
+
<span class="section-num">17</span>
|
|
1182
|
+
<h2 class="section-title">Modules</h2>
|
|
1183
|
+
<span class="section-badge badge-adv">Advanced</span>
|
|
1184
|
+
</div>
|
|
1185
|
+
<p>A Module is a black-box sub-workflow with an entry point (<span class="hl">[IN]</span>), exit point (<span class="hl">[OUT]</span>), break exit (<span class="hl">[BREAK]</span>), local vars, and an internal flow.</p>
|
|
1186
|
+
|
|
1187
|
+
<div class="code-block">
|
|
1188
|
+
<div class="code-header"><span class="code-lang">femo · module definition</span><button class="code-copy">copy</button></div>
|
|
1189
|
+
<pre><span class="k">module</span> CoderSandbox(task_var):
|
|
1190
|
+
<span class="k">vars</span>:
|
|
1191
|
+
finish = <span class="v">false</span> <span class="c"># local variable — cleared when module exits</span>
|
|
1192
|
+
|
|
1193
|
+
<span class="k">action</span> write_code <span class="at">@ai</span>(<span class="at">@coder</span>):
|
|
1194
|
+
<span class="f">prompt</span>: <span class="s">"Task: {task_var}. Use shell tools to write the code."</span>
|
|
1195
|
+
<span class="f">scope</span>: [<span class="at">@coder</span>]
|
|
1196
|
+
|
|
1197
|
+
<span class="k">action</span> submit_code <span class="at">@ai</span>(<span class="at">@coder</span>):
|
|
1198
|
+
<span class="f">prompt</span>: <span class="v">|</span>
|
|
1199
|
+
Test the code. Once confirmed correct, output:
|
|
1200
|
+
SET VARIABLE: <<finish = true>>
|
|
1201
|
+
<span class="f">out</span>: finish(bool, <span class="s">"done?"</span>)
|
|
1202
|
+
|
|
1203
|
+
<span class="k">flow</span>:
|
|
1204
|
+
<span class="p">[IN]</span> <span class="p">-></span> write_code <span class="p">-></span> submit_code <span class="p">-></span>
|
|
1205
|
+
<span class="k">fork</span>:
|
|
1206
|
+
<span class="p">-></span> if (finish == true) <span class="p">[OUT]</span>
|
|
1207
|
+
<span class="p">-></span> if (finish == false) <span class="p">[IN]</span></pre>
|
|
1208
|
+
</div>
|
|
1209
|
+
|
|
1210
|
+
<h3 class="sub">Calling a Module</h3>
|
|
1211
|
+
<div class="code-block">
|
|
1212
|
+
<div class="code-header"><span class="code-lang">femo</span><button class="code-copy">copy</button></div>
|
|
1213
|
+
<pre><span class="c"># In mainflow or another module's flow</span>
|
|
1214
|
+
<span class="p">[START]</span> <span class="p">-></span> plan <span class="p">-></span> &CoderSandbox(task_var) <span class="p">-></span> <span class="p">[END]</span>
|
|
1215
|
+
|
|
1216
|
+
<span class="c"># Combined with par for concurrent module instances</span>
|
|
1217
|
+
<span class="p">[START]</span> <span class="p">-></span> <span class="k">par</span> <span class="at">@coder</span> in coders:
|
|
1218
|
+
<span class="p">-></span> &CoderSandbox(task_list[<span class="at">@coder</span>]) <span class="p">-></span></pre>
|
|
1219
|
+
</div>
|
|
1220
|
+
|
|
1221
|
+
<div class="callout warn">
|
|
1222
|
+
<span class="callout-icon">⚠️</span>
|
|
1223
|
+
<div class="callout-body"><strong>Module local variables</strong> are cleared on exit and cannot be returned to the parent module. Use global variables to pass results out.<br><strong>Avoid module recursion</strong>: steps inside a module count as 1 globally — recursion creates infinite loops that cannot be caught by <code>max_steps</code>.</div>
|
|
1224
|
+
</div>
|
|
1225
|
+
</div>
|
|
1226
|
+
|
|
1227
|
+
<!-- ─── 18 scope ─── -->
|
|
1228
|
+
<div class="doc-section" id="sec-scope">
|
|
1229
|
+
<span class="section-anchor" id="s-scope"></span>
|
|
1230
|
+
<div class="section-header">
|
|
1231
|
+
<span class="section-num">18</span>
|
|
1232
|
+
<h2 class="section-title">scope — Perspective Isolation</h2>
|
|
1233
|
+
<span class="section-badge badge-adv">Advanced</span>
|
|
1234
|
+
</div>
|
|
1235
|
+
<p>scope defines "which actors can see this round of dialogue" — the core mechanism for perspective isolation in Femo.</p>
|
|
1236
|
+
|
|
1237
|
+
<div class="code-block">
|
|
1238
|
+
<div class="code-header"><span class="code-lang">femo · scope usage</span><button class="code-copy">copy</button></div>
|
|
1239
|
+
<pre><span class="c"># Static scope: only these two actors can see this</span>
|
|
1240
|
+
<span class="f">scope</span>: [<span class="at">@hostgod</span>, <span class="at">@wolf</span>]
|
|
1241
|
+
|
|
1242
|
+
<span class="c"># Dynamic scope: variable resolved to @actor list at runtime</span>
|
|
1243
|
+
<span class="f">scope</span>: playersInPark
|
|
1244
|
+
|
|
1245
|
+
<span class="c"># Mixed</span>
|
|
1246
|
+
<span class="f">scope</span>: [<span class="at">@hostgod</span>] + alive_players</pre>
|
|
1247
|
+
</div>
|
|
1248
|
+
|
|
1249
|
+
<p>When storing a dialogue record, the system writes the soul IDs of all actors in scope to the <code>soul_scope</code> database field. FEMO's built-in context method filters by this field, so each actor can only retrieve the context they were present for.</p>
|
|
1250
|
+
|
|
1251
|
+
<div class="callout tip">
|
|
1252
|
+
<span class="callout-icon">💡</span>
|
|
1253
|
+
<div class="callout-body"><strong>A useful analogy</strong>: scope is like a "room" — only people present can remember the conversation. More precisely: a god stores all history in a cosmic hard drive, but only those who were actually there are authorized to retrieve it. This is why perspective isolation in a Werewolf game requires just one line of scope.</div>
|
|
1254
|
+
</div>
|
|
1255
|
+
</div>
|
|
1256
|
+
|
|
1257
|
+
<!-- ─── 19 actor type system ─── -->
|
|
1258
|
+
<div class="doc-section" id="sec-actor-system">
|
|
1259
|
+
<span class="section-anchor" id="s-actor-system"></span>
|
|
1260
|
+
<div class="section-header">
|
|
1261
|
+
<span class="section-num">19</span>
|
|
1262
|
+
<h2 class="section-title">@actor Type System</h2>
|
|
1263
|
+
<span class="section-badge badge-adv">Advanced</span>
|
|
1264
|
+
</div>
|
|
1265
|
+
<p>An Actor is not just a role configuration — it is a <em>variable type</em> with identity and state, assignable and passable like any variable.</p>
|
|
1266
|
+
|
|
1267
|
+
<h3 class="sub">Dual-Perspective Attribute Access</h3>
|
|
1268
|
+
<p>The dict-perspective and entity-perspective are fully equivalent — use whichever reads more naturally:</p>
|
|
1269
|
+
|
|
1270
|
+
<div class="code-block">
|
|
1271
|
+
<div class="code-header"><span class="code-lang">femo · equivalent forms</span><button class="code-copy">copy</button></div>
|
|
1272
|
+
<pre><span class="c"># Assume vars contains: hp = {@wolf: 100, @seer: 100}</span>
|
|
1273
|
+
|
|
1274
|
+
hp.<span class="at">@wolf</span> <span class="c"> # dict perspective: look up @wolf in the hp registry</span>
|
|
1275
|
+
<span class="at">@wolf</span>.hp <span class="c"> # entity perspective: @wolf's hp attribute</span>
|
|
1276
|
+
<span class="c"># Fully equivalent — usable in prompts, assignments, and if conditions</span>
|
|
1277
|
+
|
|
1278
|
+
<span class="c"># Prompt f-string</span>
|
|
1279
|
+
<span class="s">"Your current HP is {hp.@wolf}"</span> <span class="c"># same as</span>
|
|
1280
|
+
<span class="s">"Your current HP is {@wolf.hp}"</span>
|
|
1281
|
+
|
|
1282
|
+
<span class="c"># AI assignment signal</span>
|
|
1283
|
+
SET VARIABLE: <<hp.<span class="at">@wolf</span> -= 30>> <span class="c"># same as</span>
|
|
1284
|
+
SET VARIABLE: <<<span class="at">@wolf</span>.hp -= 30>></pre>
|
|
1285
|
+
</div>
|
|
1286
|
+
|
|
1287
|
+
<h3 class="sub">Static Reserved Attributes</h3>
|
|
1288
|
+
<p>When resolving <span class="hl">@entity.attribute</span>, the following 5 reserved attributes are checked first. If not matched, the runtime looks for a same-named dict in vars:</p>
|
|
1289
|
+
<div class="def-grid">
|
|
1290
|
+
<div class="def-term">type</div> <div class="def-desc">Actor type: <code>"ai"</code> or <code>"human"</code></div>
|
|
1291
|
+
<div class="def-term">soul</div> <div class="def-desc">Soul ID (integer)</div>
|
|
1292
|
+
<div class="def-term">source</div> <div class="def-desc">Model name or user ID</div>
|
|
1293
|
+
<div class="def-term">tools</div> <div class="def-desc">Attached tool list</div>
|
|
1294
|
+
<div class="def-term">name</div> <div class="def-desc">Actor name as string</div>
|
|
1295
|
+
</div>
|
|
1296
|
+
<p>This means you can attach dynamic state to actors without modifying their definition — just create a matching dict in vars and <span class="hl">@entity.attribute</span> access works automatically.</p>
|
|
1297
|
+
</div>
|
|
1298
|
+
|
|
1299
|
+
<!-- ─── 20 SET VARIABLE ─── -->
|
|
1300
|
+
<div class="doc-section" id="sec-setvariable">
|
|
1301
|
+
<span class="section-anchor" id="s-setvariable"></span>
|
|
1302
|
+
<div class="section-header">
|
|
1303
|
+
<span class="section-num">20</span>
|
|
1304
|
+
<h2 class="section-title">AI Variable Assignment Signal</h2>
|
|
1305
|
+
<span class="section-badge badge-adv">Advanced</span>
|
|
1306
|
+
</div>
|
|
1307
|
+
<p>Guide the AI through the prompt to output assignment signals in its reply, driving updates to flow-control variables.</p>
|
|
1308
|
+
|
|
1309
|
+
<div class="code-block">
|
|
1310
|
+
<div class="code-header"><span class="code-lang">AI output examples (multiple valid formats)</span><button class="code-copy">copy</button></div>
|
|
1311
|
+
<pre><span class="c"># Standard format</span>
|
|
1312
|
+
I vote for player 3. SET VARIABLE: <<@VOTE_TARGET = <span class="at">@player3</span>>>
|
|
1313
|
+
I think prices should rise. SET VARIABLE: <<Price += 200>>
|
|
1314
|
+
I went to the park. SET VARIABLE: <<playersInPark = add(<span class="at">@soul1</span>)>>
|
|
1315
|
+
I left the park. SET VARIABLE: <<playersInPark = remove(<span class="at">@soul1</span>)>></pre>
|
|
1316
|
+
</div>
|
|
1317
|
+
|
|
1318
|
+
<h3 class="sub">Assignment Parsing Flow</h3>
|
|
1319
|
+
<ol>
|
|
1320
|
+
<li>The engine scans the full AI reply for all <code>SET VARIABLE: <<...>></code> statements</li>
|
|
1321
|
+
<li>Parses each assignment expression — successful ones update the variable immediately</li>
|
|
1322
|
+
<li>Failed parses are stored in the <span class="hl">SET_VARIABLE</span> list</li>
|
|
1323
|
+
<li>If the action has no <code>resolve</code> function, failed assignments are discarded with a warning</li>
|
|
1324
|
+
<li>If <code>resolve</code> is declared and <code>SET_VARIABLE</code> appears in its parameters, the engine passes the list for user handling</li>
|
|
1325
|
+
</ol>
|
|
1326
|
+
|
|
1327
|
+
<div class="table-wrap">
|
|
1328
|
+
<table>
|
|
1329
|
+
<tr><th>Operation</th><th>Format</th></tr>
|
|
1330
|
+
<tr><td>Direct assign</td><td><code><<VAR = value>></code></td></tr>
|
|
1331
|
+
<tr><td>Add</td><td><code><<VAR += N>></code></td></tr>
|
|
1332
|
+
<tr><td>Subtract</td><td><code><<VAR -= N>></code></td></tr>
|
|
1333
|
+
<tr><td>Append to list</td><td><code><<VAR = add(element)>></code></td></tr>
|
|
1334
|
+
<tr><td>Remove from list</td><td><code><<VAR = remove(element)>></code></td></tr>
|
|
1335
|
+
<tr><td>Dict key assign</td><td><code><<dict.@key = value>></code> or <code><<@actor.attr += N>></code></td></tr>
|
|
1336
|
+
</table>
|
|
1337
|
+
</div>
|
|
1338
|
+
</div>
|
|
1339
|
+
|
|
1340
|
+
<!-- ─── 21 Debug ─── -->
|
|
1341
|
+
<div class="doc-section" id="sec-debug">
|
|
1342
|
+
<span class="section-anchor" id="s-debug"></span>
|
|
1343
|
+
<div class="section-header">
|
|
1344
|
+
<span class="section-num">21</span>
|
|
1345
|
+
<h2 class="section-title">Debug Guide</h2>
|
|
1346
|
+
<span class="section-badge badge-debug">Debug</span>
|
|
1347
|
+
</div>
|
|
1348
|
+
|
|
1349
|
+
<h3 class="sub">Compiler Error Reference</h3>
|
|
1350
|
+
<div class="table-wrap">
|
|
1351
|
+
<table>
|
|
1352
|
+
<tr><th>Error Type</th><th>Cause</th><th>Fix</th></tr>
|
|
1353
|
+
<tr><td>Undeclared variable</td><td>An action uses a variable not declared in <code>vars</code></td><td>Declare it in <code>vars:</code> before use</td></tr>
|
|
1354
|
+
<tr><td>File not found</td><td>The path in <code>file:"path"</code> doesn't exist</td><td>Check the path; note relative path behavior</td></tr>
|
|
1355
|
+
<tr><td>Method undefined</td><td>An action references an undefined memory/context method</td><td>Verify name matches definition exactly (case-sensitive)</td></tr>
|
|
1356
|
+
<tr><td>Scope resolution failed</td><td>scope contains an unresolvable element</td><td>Ensure all variables/actors in scope are declared</td></tr>
|
|
1357
|
+
<tr><td>Loop variable name mismatch</td><td>for/par variable name doesn't match the action's parenthetical variable</td><td>Make them identical, e.g. both <code>@speaker</code></td></tr>
|
|
1358
|
+
<tr><td>Database constraint violation</td><td>A database operation violates a constraint</td><td>Engine re-throws the exception — inspect the database schema</td></tr>
|
|
1359
|
+
<tr><td>@func out key mismatch</td><td>Python return dict keys don't match <code>out</code> variable names</td><td>Ensure a 1-to-1 match between keys and declared out names</td></tr>
|
|
1360
|
+
</table>
|
|
1361
|
+
</div>
|
|
1362
|
+
|
|
1363
|
+
<h3 class="sub">Common Runtime Issues</h3>
|
|
1364
|
+
|
|
1365
|
+
<div class="callout warn">
|
|
1366
|
+
<span class="callout-icon">🔎</span>
|
|
1367
|
+
<div class="callout-body"><strong>AI doesn't output the assignment variable</strong><br>
|
|
1368
|
+
Check that the prompt's instruction is explicit enough. Recommend stating the exact format in the prompt: <code>After your analysis, you must output SET VARIABLE: <<VAR = value>></code>. You can also use a <code>resolve</code> function to handle non-standard AI output.</div>
|
|
1369
|
+
</div>
|
|
1370
|
+
|
|
1371
|
+
<div class="callout warn">
|
|
1372
|
+
<span class="callout-icon">🔎</span>
|
|
1373
|
+
<div class="callout-body"><strong>AI actor says things it shouldn't (perspective leak)</strong><br>
|
|
1374
|
+
Check scope configuration. Is each action's scope correctly isolated? For example, werewolf nighttime speech should have scope limited to wolf team members — excluding the Seer.</div>
|
|
1375
|
+
</div>
|
|
1376
|
+
|
|
1377
|
+
<div class="callout warn">
|
|
1378
|
+
<span class="callout-icon">🔎</span>
|
|
1379
|
+
<div class="callout-body"><strong>Loop never ends</strong><br>
|
|
1380
|
+
Check exit conditions: ① Is the for loop's termination condition correctly iterating through the array? ② Does the module's fork condition correctly point to [OUT]? ③ Is there recursion inside a module? (Should be avoided — see section 17.)</div>
|
|
1381
|
+
</div>
|
|
1382
|
+
|
|
1383
|
+
<div class="callout warn">
|
|
1384
|
+
<span class="callout-icon">🔎</span>
|
|
1385
|
+
<div class="callout-body"><strong>@func receives empty parameters</strong><br>
|
|
1386
|
+
Check: ① In auto-inference mode, do the Python function param names exactly match variable names in <code>vars</code>? ② When an @actor variable is passed to Python, it arrives as a dict, not a string — access fields with <code>actor.get("soul")</code> etc.</div>
|
|
1387
|
+
</div>
|
|
1388
|
+
|
|
1389
|
+
<div class="callout warn">
|
|
1390
|
+
<span class="callout-icon">🔎</span>
|
|
1391
|
+
<div class="callout-body"><strong>Module local variables "leaking"</strong><br>
|
|
1392
|
+
Module vars are cleared on exit and cannot be returned to the parent. To pass results out of a module, pre-declare a variable in the mainflow-level global vars, then update it from inside the module via the <code>SET VARIABLE</code> signal — don't rely on module-local variables for output.</div>
|
|
1393
|
+
</div>
|
|
1394
|
+
|
|
1395
|
+
<h3 class="sub">Debug Tips</h3>
|
|
1396
|
+
<ul>
|
|
1397
|
+
<li><strong>Narrow scope</strong>: validate individual action behavior with a simple script first, then compose into complex flows</li>
|
|
1398
|
+
<li><strong>Add @hostgod to all scopes</strong>: gives one "god-mode" actor access to all scopes, making it easy to review the full dialogue history</li>
|
|
1399
|
+
<li><strong>Use the super_debug.femo template</strong>: the project's built-in debug script features two concurrent branches and multi-turn discussion — ideal for tracking subtle bugs</li>
|
|
1400
|
+
<li><strong>Insert human nodes anywhere</strong>: add a <code>@human</code> node before or after key actions to pause, interject, or inspect current state</li>
|
|
1401
|
+
<li><strong>Inspect the database</strong>: all dialogue records are stored in the database — query the <code>soul_scope</code> field directly to confirm perspective isolation is working</li>
|
|
1402
|
+
</ul>
|
|
1403
|
+
</div>
|
|
1404
|
+
|
|
1405
|
+
<!-- ─── 22 Full Example ─── -->
|
|
1406
|
+
<div class="doc-section" id="sec-example">
|
|
1407
|
+
<span class="section-anchor" id="s-example"></span>
|
|
1408
|
+
<div class="section-header">
|
|
1409
|
+
<span class="section-num">22</span>
|
|
1410
|
+
<h2 class="section-title">Complete Example</h2>
|
|
1411
|
+
<span class="section-badge badge-core">Core</span>
|
|
1412
|
+
</div>
|
|
1413
|
+
<p>A fully runnable script featuring AI actors, memory, context, and a concurrent voting round:</p>
|
|
1414
|
+
|
|
1415
|
+
<div class="code-block">
|
|
1416
|
+
<div class="code-header"><span class="code-lang">femo · complete_example.femo</span><button class="code-copy">copy</button></div>
|
|
1417
|
+
<pre><span class="k">meta</span>:
|
|
1418
|
+
name = <span class="s">"Three-Person Chat Room"</span>
|
|
1419
|
+
database = file:<span class="s">"chat.db"</span>
|
|
1420
|
+
owner = [<span class="v">1</span>]
|
|
1421
|
+
session = <span class="k">new</span>
|
|
1422
|
+
|
|
1423
|
+
<span class="k">vars</span>:
|
|
1424
|
+
memory_text = <span class="s">""</span>
|
|
1425
|
+
context_text = <span class="s">""</span>
|
|
1426
|
+
vote_results = {}
|
|
1427
|
+
winner = <span class="s">""</span>
|
|
1428
|
+
|
|
1429
|
+
<span class="k">code</span>:
|
|
1430
|
+
memfile = file:<span class="s">"femoBridges/MemoryExample.py"</span>
|
|
1431
|
+
ctxfile = file:<span class="s">"femoBridges/ContextExample.py"</span>
|
|
1432
|
+
logic = file:<span class="s">"vote_logic.py"</span>
|
|
1433
|
+
|
|
1434
|
+
<span class="k">actors</span>:
|
|
1435
|
+
ai <span class="at">@alice</span> = soul:<span class="v">1</span>, source:<span class="v">deepseek</span>
|
|
1436
|
+
ai <span class="at">@bob</span> = soul:<span class="v">2</span>, source:<span class="v">glm5</span>
|
|
1437
|
+
human <span class="at">@me</span> = soul:<span class="v">0</span>, source:<span class="v">1</span>
|
|
1438
|
+
|
|
1439
|
+
<span class="k">memory</span> rag10(memfile.retrieve_example):
|
|
1440
|
+
<span class="f">in</span>: prompt, session_id, <span class="at">@actor</span>
|
|
1441
|
+
<span class="f">out</span>: memory_text
|
|
1442
|
+
|
|
1443
|
+
<span class="k">context</span> thisSession(ctxfile.findThisSession):
|
|
1444
|
+
<span class="f">in</span>: session, <span class="at">@actor</span>
|
|
1445
|
+
<span class="f">out</span>: context_text
|
|
1446
|
+
|
|
1447
|
+
<span class="c"># ── Actions ──</span>
|
|
1448
|
+
|
|
1449
|
+
<span class="k">action</span> alice_speak <span class="at">@ai</span>(<span class="at">@alice</span>):
|
|
1450
|
+
<span class="f">prompt</span>: <span class="s">"Share a brief thought on today's topic with the group."</span>
|
|
1451
|
+
<span class="f">scope</span>: [<span class="at">@alice</span>, <span class="at">@bob</span>, <span class="at">@me</span>]
|
|
1452
|
+
|
|
1453
|
+
<span class="k">action</span> bob_speak <span class="at">@ai</span>(<span class="at">@bob</span>):
|
|
1454
|
+
<span class="f">prompt</span>: <span class="s">"Respond briefly to Alice's message."</span>
|
|
1455
|
+
<span class="f">scope</span>: [<span class="at">@alice</span>, <span class="at">@bob</span>, <span class="at">@me</span>]
|
|
1456
|
+
|
|
1457
|
+
<span class="k">action</span> me_speak <span class="at">@human</span>(<span class="at">@me</span>):
|
|
1458
|
+
<span class="f">prompt</span>: <span class="s">"What would you like to say?"</span>
|
|
1459
|
+
<span class="f">scope</span>: [<span class="at">@alice</span>, <span class="at">@bob</span>, <span class="at">@me</span>]
|
|
1460
|
+
|
|
1461
|
+
<span class="c"># Concurrent voting: Alice and Bob vote simultaneously</span>
|
|
1462
|
+
<span class="k">action</span> cast_vote <span class="at">@ai</span>(<span class="at">@voter</span>):
|
|
1463
|
+
<span class="f">prompt</span>: <span class="v">|</span>
|
|
1464
|
+
Vote for today's best speaker (@alice or @bob).
|
|
1465
|
+
Output: SET VARIABLE: <<vote_results.<span class="at">@voter</span> = @voted_name>>
|
|
1466
|
+
<span class="f">scope</span>: [<span class="at">@voter</span>]
|
|
1467
|
+
<span class="f">out</span>: vote_results.<span class="at">@voter</span>(string, <span class="s">"vote target"</span>)
|
|
1468
|
+
|
|
1469
|
+
<span class="k">action</span> tally <span class="at">@func</span>(logic.tally_votes):
|
|
1470
|
+
<span class="f">in</span>: votes = vote_results
|
|
1471
|
+
<span class="f">out</span>: winner
|
|
1472
|
+
|
|
1473
|
+
<span class="k">action</span> announce <span class="at">@ai</span>(<span class="at">@alice</span>):
|
|
1474
|
+
<span class="f">prompt</span>: <span class="s">"Vote results: {winner} received the most votes. Congratulations!"</span>
|
|
1475
|
+
<span class="f">scope</span>: [<span class="at">@alice</span>, <span class="at">@bob</span>, <span class="at">@me</span>]
|
|
1476
|
+
|
|
1477
|
+
<span class="k">mainflow</span>:
|
|
1478
|
+
<span class="p">[START]</span> <span class="p">-></span> me_speak <span class="p">-></span> alice_speak <span class="p">-></span> bob_speak <span class="p">-></span> <span class="p">[VOTE]</span>
|
|
1479
|
+
|
|
1480
|
+
<span class="c"># Concurrent vote — everyone votes at the same time</span>
|
|
1481
|
+
<span class="p">[VOTE]</span> <span class="p">-></span> <span class="k">par</span> <span class="at">@voter</span> in [<span class="at">@alice</span>, <span class="at">@bob</span>]:
|
|
1482
|
+
<span class="p">-></span> cast_vote <span class="p">-></span>
|
|
1483
|
+
<span class="p">-></span> <span class="p">[tally]</span>: tally
|
|
1484
|
+
<span class="p">[tally]</span> <span class="p">-></span> announce <span class="p">-></span> <span class="p">[END]</span></pre>
|
|
1485
|
+
</div>
|
|
1486
|
+
</div>
|
|
1487
|
+
|
|
1488
|
+
<!-- ─── 23 Prompt Blocks ─── -->
|
|
1489
|
+
<div class="doc-section" id="sec-blocks">
|
|
1490
|
+
<span class="section-anchor" id="s-blocks"></span>
|
|
1491
|
+
<div class="section-header">
|
|
1492
|
+
<span class="section-num">23</span>
|
|
1493
|
+
<h2 class="section-title">Prompt Block Collection</h2>
|
|
1494
|
+
<span class="section-badge badge-adv">Dev</span>
|
|
1495
|
+
</div>
|
|
1496
|
+
<p>Before executing each action, the engine automatically collects the following standard blocks and returns them as a dict for the external prompt assembler. The engine only collects and returns the dict — the external framework decides how to assemble them into system/user prompts.</p>
|
|
1497
|
+
|
|
1498
|
+
<div class="table-wrap">
|
|
1499
|
+
<table>
|
|
1500
|
+
<tr><th>Block Key</th><th>Content</th><th>Source</th></tr>
|
|
1501
|
+
<tr><td><code>basic_safety</code></td><td>Safety policy</td><td><code>meta.system_safety</code></td></tr>
|
|
1502
|
+
<tr><td><code>basic_output</code></td><td>Output quality guidelines</td><td><code>meta.output_style</code></td></tr>
|
|
1503
|
+
<tr><td><code>soul</code></td><td>Character description (system prompt fragment)</td><td>Database <code>souls</code> table, keyed by the current Actor's soul_id</td></tr>
|
|
1504
|
+
<tr><td><code>user_info</code></td><td>User profile</td><td>Database <code>users</code> table, keyed by <code>meta.owner</code></td></tr>
|
|
1505
|
+
<tr><td><code>memory</code></td><td>Memory retrieval result</td><td>User-defined memory function return value</td></tr>
|
|
1506
|
+
<tr><td><code>context</code></td><td>Dialogue history context</td><td>User-defined context function / built-in default</td></tr>
|
|
1507
|
+
<tr><td><code>user_input</code></td><td>Current prompt (after variable substitution)</td><td>The current action's <code>prompt</code> field</td></tr>
|
|
1508
|
+
</table>
|
|
1509
|
+
</div>
|
|
1510
|
+
|
|
1511
|
+
<div class="callout info">
|
|
1512
|
+
<span class="callout-icon">ℹ️</span>
|
|
1513
|
+
<div class="callout-body">Building-block architecture: the engine only collects blocks — it's not bound to any prompt layout or LLM calling convention. To swap out the LLM bridge module, just wire it up to this blocks dict.</div>
|
|
1514
|
+
</div>
|
|
1515
|
+
</div>
|
|
1516
|
+
|
|
1517
|
+
<!-- ─── 24 Session ─── -->
|
|
1518
|
+
<div class="doc-section" id="sec-session">
|
|
1519
|
+
<span class="section-anchor" id="s-session"></span>
|
|
1520
|
+
<div class="section-header">
|
|
1521
|
+
<span class="section-num">24</span>
|
|
1522
|
+
<h2 class="section-title">Session & Turn Management</h2>
|
|
1523
|
+
<span class="section-badge badge-adv">Dev</span>
|
|
1524
|
+
</div>
|
|
1525
|
+
|
|
1526
|
+
<div class="table-wrap">
|
|
1527
|
+
<table>
|
|
1528
|
+
<tr><th>Scenario</th><th>Behavior</th></tr>
|
|
1529
|
+
<tr><td><code>meta.session</code> not specified or <code>new</code></td><td>Creates a new session (database max session_id + 1), turn = 1</td></tr>
|
|
1530
|
+
<tr><td><code>meta.session</code> set to a number</td><td>Resumes that session; turn starts from that session's max turn + 1</td></tr>
|
|
1531
|
+
<tr><td>Specified session doesn't exist</td><td>Error and exit</td></tr>
|
|
1532
|
+
</table>
|
|
1533
|
+
</div>
|
|
1534
|
+
|
|
1535
|
+
<ul>
|
|
1536
|
+
<li>After each <strong>human utterance</strong>: <code>turn_count += 1</code>, <code>step_idx = 0</code></li>
|
|
1537
|
+
<li>Within the same turn, each <strong>AI utterance</strong> increments <code>step_idx += 1</code></li>
|
|
1538
|
+
<li>When creating a new session, <code>meta.name</code> is automatically written to the <code>sessions.title</code> field</li>
|
|
1539
|
+
</ul>
|
|
1540
|
+
</div>
|
|
1541
|
+
|
|
1542
|
+
<!-- ─── 25 Storage ─── -->
|
|
1543
|
+
<div class="doc-section" id="sec-storage">
|
|
1544
|
+
<span class="section-anchor" id="s-storage"></span>
|
|
1545
|
+
<div class="section-header">
|
|
1546
|
+
<span class="section-num">25</span>
|
|
1547
|
+
<h2 class="section-title">Dialog Storage Rules</h2>
|
|
1548
|
+
<span class="section-badge badge-adv">Dev</span>
|
|
1549
|
+
</div>
|
|
1550
|
+
|
|
1551
|
+
<h3 class="sub">When Records Are Stored</h3>
|
|
1552
|
+
<ul>
|
|
1553
|
+
<li><strong>Human utterance (@human action)</strong>: stored in the <code>dialog</code> table, then turn + 1</li>
|
|
1554
|
+
<li><strong>AI reply (@ai action)</strong>: stored in the <code>react_steps</code> table, <code>step_idx</code> incremented</li>
|
|
1555
|
+
</ul>
|
|
1556
|
+
|
|
1557
|
+
<h3 class="sub">Automatic Scope Injection</h3>
|
|
1558
|
+
<p>Each record automatically includes the speaker's own ID (AI soul_id or human user_id) plus all user_ids from <code>meta.owner</code>. After injection, 0 is removed and the list is deduplicated, then stored in the <code>user_scope</code> and <code>soul_scope</code> fields.</p>
|
|
1559
|
+
|
|
1560
|
+
<div class="callout info">
|
|
1561
|
+
<span class="callout-icon">ℹ️</span>
|
|
1562
|
+
<div class="callout-body">This is the underlying mechanism for scope-based perspective isolation — context retrieval filters by <code>soul_scope</code>, so each actor can only see the history they were present for.</div>
|
|
1563
|
+
</div>
|
|
1564
|
+
</div>
|
|
1565
|
+
|
|
1566
|
+
<!-- ─── 26 DB ─── -->
|
|
1567
|
+
<div class="doc-section" id="sec-db">
|
|
1568
|
+
<span class="section-anchor" id="s-db"></span>
|
|
1569
|
+
<div class="section-header">
|
|
1570
|
+
<span class="section-num">26</span>
|
|
1571
|
+
<h2 class="section-title">Database Schema</h2>
|
|
1572
|
+
<span class="section-badge badge-adv">Dev</span>
|
|
1573
|
+
</div>
|
|
1574
|
+
<p>Femo uses SQLite with a default file at <span class="hl">./chronica.wor</span>, configurable via the <span class="hl">database</span> field in <code>meta</code>.</p>
|
|
1575
|
+
|
|
1576
|
+
<div class="code-block">
|
|
1577
|
+
<div class="code-header"><span class="code-lang">sql · full schema</span><button class="code-copy">copy</button></div>
|
|
1578
|
+
<pre>CREATE TABLE IF NOT EXISTS sessions (
|
|
1579
|
+
session_id INTEGER PRIMARY KEY,
|
|
1580
|
+
title TEXT DEFAULT '',
|
|
1581
|
+
owner TEXT DEFAULT '',
|
|
1582
|
+
participants TEXT DEFAULT '[]'
|
|
1583
|
+
);
|
|
1584
|
+
|
|
1585
|
+
CREATE TABLE IF NOT EXISTS dialog (
|
|
1586
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
1587
|
+
session_id INTEGER,
|
|
1588
|
+
turn_id INTEGER,
|
|
1589
|
+
oratio_idx INTEGER DEFAULT 0,
|
|
1590
|
+
timestamp INTEGER DEFAULT 0,
|
|
1591
|
+
has_user_files INTEGER DEFAULT 0,
|
|
1592
|
+
ai_steps_count INTEGER DEFAULT 0,
|
|
1593
|
+
user_prompt TEXT DEFAULT '',
|
|
1594
|
+
user_id TEXT DEFAULT '',
|
|
1595
|
+
soul_id TEXT DEFAULT '',
|
|
1596
|
+
user_scope TEXT DEFAULT '[]',
|
|
1597
|
+
soul_scope TEXT DEFAULT '[]',
|
|
1598
|
+
work_mode TEXT DEFAULT 'chat'
|
|
1599
|
+
);
|
|
1600
|
+
|
|
1601
|
+
CREATE TABLE IF NOT EXISTS files (
|
|
1602
|
+
file_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
1603
|
+
session_id INTEGER,
|
|
1604
|
+
turn_id INTEGER,
|
|
1605
|
+
file_idx INTEGER DEFAULT 0,
|
|
1606
|
+
file_name TEXT DEFAULT '',
|
|
1607
|
+
file_content TEXT DEFAULT ''
|
|
1608
|
+
);
|
|
1609
|
+
|
|
1610
|
+
CREATE TABLE IF NOT EXISTS react_steps (
|
|
1611
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
1612
|
+
session_id INTEGER,
|
|
1613
|
+
turn_id INTEGER,
|
|
1614
|
+
step_idx INTEGER DEFAULT 0,
|
|
1615
|
+
timestamp INTEGER DEFAULT 0,
|
|
1616
|
+
cot TEXT DEFAULT '',
|
|
1617
|
+
response TEXT DEFAULT '',
|
|
1618
|
+
tool_call TEXT DEFAULT '',
|
|
1619
|
+
tool_result TEXT DEFAULT '',
|
|
1620
|
+
model_id TEXT DEFAULT '',
|
|
1621
|
+
soul_id TEXT DEFAULT '',
|
|
1622
|
+
user_scope TEXT DEFAULT '[]',
|
|
1623
|
+
soul_scope TEXT DEFAULT '[]'
|
|
1624
|
+
);
|
|
1625
|
+
|
|
1626
|
+
CREATE TABLE IF NOT EXISTS souls (
|
|
1627
|
+
idx INTEGER PRIMARY KEY,
|
|
1628
|
+
soul_id TEXT,
|
|
1629
|
+
soul_name TEXT DEFAULT '',
|
|
1630
|
+
description TEXT DEFAULT '',
|
|
1631
|
+
user_id TEXT,
|
|
1632
|
+
created_by TEXT
|
|
1633
|
+
);
|
|
1634
|
+
|
|
1635
|
+
CREATE TABLE IF NOT EXISTS users (
|
|
1636
|
+
idx INTEGER PRIMARY KEY,
|
|
1637
|
+
user_id TEXT,
|
|
1638
|
+
user_name TEXT DEFAULT '',
|
|
1639
|
+
profile TEXT DEFAULT ''
|
|
1640
|
+
);</pre>
|
|
1641
|
+
</div>
|
|
1642
|
+
</div>
|
|
1643
|
+
|
|
1644
|
+
<!-- ─── 27 Engine ─── -->
|
|
1645
|
+
<div class="doc-section" id="sec-engine">
|
|
1646
|
+
<span class="section-anchor" id="s-engine"></span>
|
|
1647
|
+
<div class="section-header">
|
|
1648
|
+
<span class="section-num">27</span>
|
|
1649
|
+
<h2 class="section-title">Async Engine Architecture</h2>
|
|
1650
|
+
<span class="section-badge badge-adv">Dev</span>
|
|
1651
|
+
</div>
|
|
1652
|
+
<p><span class="hl">AsyncEngine</span> (located at <code>femoCompiler/femoAsync.py</code>) is the hub of the entire concurrent system — managing all executors, scheduling coroutine tasks, and providing unified async primitives.</p>
|
|
1653
|
+
|
|
1654
|
+
<h3 class="sub">Core Idea: Scheduling and Execution Are Decoupled</h3>
|
|
1655
|
+
<p>The engine follows a <em>"single-threaded brain, delegated heavy lifting"</em> model:</p>
|
|
1656
|
+
<ul>
|
|
1657
|
+
<li><strong>asyncio event loop</strong>: the sole scheduler, single-threaded, orchestrates all Agent coroutines — no operation blocks the event loop</li>
|
|
1658
|
+
<li><strong>Heavy tasks (CPU-intensive, synchronous I/O, human input waiting)</strong>: always delegated to independent execution pools (process pool or thread pool); the main loop only awaits results</li>
|
|
1659
|
+
</ul>
|
|
1660
|
+
<p>This separation keeps the main loop always responsive — even if one branch is running a long computation or waiting for an LLM, other branches continue advancing.</p>
|
|
1661
|
+
|
|
1662
|
+
<h3 class="sub">Three Executor Types</h3>
|
|
1663
|
+
<div class="def-grid">
|
|
1664
|
+
<div class="def-term">Process Pool</div>
|
|
1665
|
+
<div class="def-desc">CPU-intensive tasks. Size auto-adapts to CPU core count. Tasks queue automatically — when all workers are busy, subsequent tasks wait in an internal queue without being dropped.</div>
|
|
1666
|
+
<div class="def-term">I/O Thread Pool</div>
|
|
1667
|
+
<div class="def-desc">Synchronous blocking I/O (LLM API calls) and @func user code. Each thread launches a persistent background event loop at creation time, completely eliminating <code>no running event loop</code> errors.</div>
|
|
1668
|
+
<div class="def-term">Human Input Manager</div>
|
|
1669
|
+
<div class="def-desc">Thread-safe async waiting built on <code>threading.Event</code>. A coroutine calling <code>wait_for_input</code> suspends; the external side wakes it via <code>provide_input</code>. Supports timeouts.</div>
|
|
1670
|
+
</div>
|
|
1671
|
+
|
|
1672
|
+
<h3 class="sub">Task Scheduling and Join Modes</h3>
|
|
1673
|
+
<p>Each Agent branch (fork branch) is an <span class="hl">asyncio.Task</span>. At fork time, <code>engine.create_task()</code> creates and auto-tracks tasks; at join time, <span class="hl">gather_with_cancel</span> waits or cancels them uniformly.</p>
|
|
1674
|
+
<div class="table-wrap">
|
|
1675
|
+
<table>
|
|
1676
|
+
<tr><th>Join Mode</th><th>Behavior</th></tr>
|
|
1677
|
+
<tr><td><code>all</code></td><td>Wait for all branches to complete</td></tr>
|
|
1678
|
+
<tr><td><code>any</code></td><td>Cancel all others once any one completes</td></tr>
|
|
1679
|
+
<tr><td><code>n</code></td><td>Cancel all others once the specified count complete</td></tr>
|
|
1680
|
+
</table>
|
|
1681
|
+
</div>
|
|
1682
|
+
|
|
1683
|
+
<h3 class="sub">Context Isolation</h3>
|
|
1684
|
+
<p>Python's standard library <span class="hl">contextvars</span> automatically isolates context variables for each coroutine/thread. Each Agent branch has an independent <code>ExecutionContext</code> — internal variables like <code>node_name</code> and loop variables don't interfere with each other. No manual locking required.</p>
|
|
1685
|
+
</div>
|
|
1686
|
+
|
|
1687
|
+
<!-- ─── 28 Runtime ─── -->
|
|
1688
|
+
<div class="doc-section" id="sec-runtime">
|
|
1689
|
+
<span class="section-anchor" id="s-runtime"></span>
|
|
1690
|
+
<div class="section-header">
|
|
1691
|
+
<span class="section-num">28</span>
|
|
1692
|
+
<h2 class="section-title">Runtime Integration</h2>
|
|
1693
|
+
<span class="section-badge badge-adv">Dev</span>
|
|
1694
|
+
</div>
|
|
1695
|
+
<p><span class="hl">FEMORunner</span> (located at <code>femoCompiler/FEMO_runtime.py</code>) is the workflow executor. It holds an <code>AsyncEngine</code> instance and delegates all concurrency needs to it.</p>
|
|
1696
|
+
|
|
1697
|
+
<h3 class="sub">Node Execution Routing</h3>
|
|
1698
|
+
<div class="table-wrap">
|
|
1699
|
+
<table>
|
|
1700
|
+
<tr><th>Node Type</th><th>Execution Method</th></tr>
|
|
1701
|
+
<tr><td><code>@func</code></td><td><code>engine.run_in_thread</code>, executed in the thread pool (may auto-switch to process pool based on complexity in the future)</td></tr>
|
|
1702
|
+
<tr><td><code>@ai</code></td><td>LLM calls submitted via <code>engine.run_in_thread</code>; streaming callbacks pushed back safely to the event loop via <code>engine.schedule_threadsafe</code></td></tr>
|
|
1703
|
+
<tr><td><code>@human</code></td><td>In FastAPI mode: the coroutine suspends waiting for frontend input; in CLI mode: the read function is submitted to the thread pool, not blocking the main loop</td></tr>
|
|
1704
|
+
</table>
|
|
1705
|
+
</div>
|
|
1706
|
+
|
|
1707
|
+
<h3 class="sub">Flow Control Primitive → Engine Mapping</h3>
|
|
1708
|
+
<div class="table-wrap">
|
|
1709
|
+
<table>
|
|
1710
|
+
<tr><th>Flow Syntax</th><th>Runtime Implementation</th></tr>
|
|
1711
|
+
<tr><td>Fork</td><td><code>_run_fork</code> creates an <code>engine.create_task()</code> for each branch, stored in the <code>_join_tasks</code> dict</td></tr>
|
|
1712
|
+
<tr><td>Join</td><td><code>_run_join</code> retrieves the task list and calls <code>engine.gather_with_cancel</code> with the configured join mode</td></tr>
|
|
1713
|
+
<tr><td>For loop</td><td>Iterates inside a normal <code>async</code> method; loop body re-enters the gateway via a back-edge — no special engine support needed</td></tr>
|
|
1714
|
+
</table>
|
|
1715
|
+
</div>
|
|
1716
|
+
|
|
1717
|
+
<h3 class="sub">Main Flow Entry Point</h3>
|
|
1718
|
+
<p><code>FEMORunner.run()</code> is the synchronous entry point. It detects whether an event loop is already running:</p>
|
|
1719
|
+
<ul>
|
|
1720
|
+
<li><strong>CLI mode</strong> (no event loop): calls <code>asyncio.run(self.run_async())</code> to start a new loop</li>
|
|
1721
|
+
<li><strong>FastAPI mode</strong> (loop already running): directly <code>await runner.run_async()</code></li>
|
|
1722
|
+
</ul>
|
|
1723
|
+
</div>
|
|
1724
|
+
|
|
1725
|
+
<!-- ─── 29 Dev Guide ─── -->
|
|
1726
|
+
<div class="doc-section" id="sec-devguide">
|
|
1727
|
+
<span class="section-anchor" id="s-devguide"></span>
|
|
1728
|
+
<div class="section-header">
|
|
1729
|
+
<span class="section-num">29</span>
|
|
1730
|
+
<h2 class="section-title">Tuning & Extension Guide</h2>
|
|
1731
|
+
<span class="section-badge badge-adv">Dev</span>
|
|
1732
|
+
</div>
|
|
1733
|
+
|
|
1734
|
+
<h3 class="sub">Thread Pool & Process Pool Tuning</h3>
|
|
1735
|
+
<div class="table-wrap">
|
|
1736
|
+
<table>
|
|
1737
|
+
<tr><th>Executor</th><th>Default</th><th>Tuning Advice</th></tr>
|
|
1738
|
+
<tr><td>I/O Thread Pool</td><td>10 threads</td><td>Increase to 20–30 for heavy concurrent LLM calls; keep small when a dedicated AI thread pool is split out. Configure via <code>thread_workers</code> parameter</td></tr>
|
|
1739
|
+
<tr><td>Process Pool</td><td>Auto-detected CPU core count</td><td>Increase when there are many CPU-intensive @func nodes. Configure via <code>cpu_workers</code> param or <code>PROCESS_WORKERS</code> env var</td></tr>
|
|
1740
|
+
</table>
|
|
1741
|
+
</div>
|
|
1742
|
+
|
|
1743
|
+
<h3 class="sub">Adding a New Executor Type (Example: @gpu)</h3>
|
|
1744
|
+
<div class="code-block">
|
|
1745
|
+
<div class="code-header"><span class="code-lang">python · femoAsync.py</span><button class="code-copy">copy</button></div>
|
|
1746
|
+
<pre><span class="c"># 1. Add a dedicated executor in AsyncEngine.__init__</span>
|
|
1747
|
+
self.gpu_pool = ThreadPoolExecutor(max_workers=<span class="v">2</span>)
|
|
1748
|
+
self._gpu_semaphore = asyncio.Semaphore(<span class="v">2</span>)
|
|
1749
|
+
|
|
1750
|
+
<span class="c"># Add a new method</span>
|
|
1751
|
+
async def run_gpu(self, func, *args, **kwargs):
|
|
1752
|
+
async with self._gpu_semaphore:
|
|
1753
|
+
loop = asyncio.get_running_loop()
|
|
1754
|
+
return await loop.run_in_executor(self.gpu_pool, func, *args, **kwargs)</pre>
|
|
1755
|
+
</div>
|
|
1756
|
+
<div class="code-block">
|
|
1757
|
+
<div class="code-header"><span class="code-lang">python · FEMO_runtime.py</span><button class="code-copy">copy</button></div>
|
|
1758
|
+
<pre><span class="c"># 2. Add routing in _exec_action_def</span>
|
|
1759
|
+
elif etype == <span class="s">'gpu'</span>:
|
|
1760
|
+
return await self._exec_gpu(ad, eparam)
|
|
1761
|
+
|
|
1762
|
+
<span class="c"># 3. Implement _exec_gpu, modeled after _exec_func, calling self.engine.run_gpu(...)</span></pre>
|
|
1763
|
+
</div>
|
|
1764
|
+
|
|
1765
|
+
<h3 class="sub">Troubleshooting</h3>
|
|
1766
|
+
<div class="callout warn">
|
|
1767
|
+
<span class="callout-icon">🔎</span>
|
|
1768
|
+
<div class="callout-body"><strong>Frontend receives no node info (node_name is empty)</strong><br>The main flow didn't create a top-level <code>ExecutionContext</code>. Ensure <code>run_async</code> is wrapped in <code>with ExecutionContext("__main__"):</code>.</div>
|
|
1769
|
+
</div>
|
|
1770
|
+
<div class="callout warn">
|
|
1771
|
+
<span class="callout-icon">🔎</span>
|
|
1772
|
+
<div class="callout-body"><strong>Flow silently exits with no errors</strong><br>Entry inference failed (<code>flow.entry</code> is empty, or all nodes have in-edges). Check whether the workflow explicitly declares a <code>[START]</code> node.</div>
|
|
1773
|
+
</div>
|
|
1774
|
+
<div class="callout warn">
|
|
1775
|
+
<span class="callout-icon">🔎</span>
|
|
1776
|
+
<div class="callout-body"><strong>AI calls report <code>no running event loop</code></strong><br>Confirm <code>AsyncEngine</code>'s thread pool is configured with an <code>initializer</code> (to start a background event loop for each thread). This is built-in engine behavior and normally requires no extra config — if this error appears, the engine initialization may have been bypassed.</div>
|
|
1777
|
+
</div>
|
|
1778
|
+
<div class="callout warn">
|
|
1779
|
+
<span class="callout-icon">🔎</span>
|
|
1780
|
+
<div class="callout-body"><strong>All fork branches execute unconditionally</strong><br><code>_run_fork</code> is not evaluating condition edges. Confirm the branch entry collection logic calls <code>self._eval_condition(e.condition)</code> to filter out false conditions.</div>
|
|
1781
|
+
</div>
|
|
1782
|
+
|
|
1783
|
+
<h3 class="sub">Scaling from Single Machine to Distributed</h3>
|
|
1784
|
+
<p>The current architecture already decouples the scheduling layer (<code>FEMORunner</code> / <code>AsyncEngine</code>) from the execution layer (thread pools, process pools), making distributed scaling natural:</p>
|
|
1785
|
+
<ul>
|
|
1786
|
+
<li><strong>Scheduler cluster</strong>: deploy multiple stateless <code>FEMORunner</code> instances behind a load balancer</li>
|
|
1787
|
+
<li><strong>CPU Worker cluster</strong>: route CPU-intensive @func nodes to dedicated Python Workers via Redis Streams or RabbitMQ</li>
|
|
1788
|
+
<li><strong>GPU inference cluster</strong>: call GPU inference nodes via HTTP/gRPC to deployed model services (e.g. vLLM)</li>
|
|
1789
|
+
<li><strong>Human input management</strong>: swap <code>HumanInputManager</code>'s backend to Redis Pub/Sub to support cross-machine input waiting and wake-up</li>
|
|
1790
|
+
</ul>
|
|
1791
|
+
</div>
|
|
1792
|
+
|
|
1793
|
+
<!-- ─── 30 Engine API ─── -->
|
|
1794
|
+
<div class="doc-section" id="sec-engineapi">
|
|
1795
|
+
<span class="section-anchor" id="s-engineapi"></span>
|
|
1796
|
+
<div class="section-header">
|
|
1797
|
+
<span class="section-num">30</span>
|
|
1798
|
+
<h2 class="section-title">AsyncEngine API Reference</h2>
|
|
1799
|
+
<span class="section-badge badge-adv">Dev</span>
|
|
1800
|
+
</div>
|
|
1801
|
+
|
|
1802
|
+
<div class="table-wrap">
|
|
1803
|
+
<table>
|
|
1804
|
+
<tr><th>Method / Property</th><th>Purpose</th><th>Notes</th></tr>
|
|
1805
|
+
<tr><td><code>__init__(cpu_workers, thread_workers)</code></td><td>Initialize engine</td><td>Creates process pool, thread pool, and human input manager</td></tr>
|
|
1806
|
+
<tr><td><code>run_in_process(func, *args, **kwargs)</code></td><td>Execute CPU-intensive task</td><td>Submitted to process pool, auto-queued</td></tr>
|
|
1807
|
+
<tr><td><code>run_in_thread(func, *args, **kwargs)</code></td><td>Execute synchronous I/O or regular functions</td><td>Submitted to thread pool (with built-in event loop)</td></tr>
|
|
1808
|
+
<tr><td><code>create_task(coro)</code></td><td>Create a coroutine task</td><td>Used for fork branches; auto-tracked</td></tr>
|
|
1809
|
+
<tr><td><code>gather_with_cancel(tasks, return_when, count)</code></td><td>Wait for multiple tasks</td><td>Supports <code>all</code> / <code>any</code> / <code>n</code> modes</td></tr>
|
|
1810
|
+
<tr><td><code>gather(*coros, return_exceptions)</code></td><td>Concurrently await multiple coroutines</td><td>Wraps <code>asyncio.gather</code></td></tr>
|
|
1811
|
+
<tr><td><code>schedule_threadsafe(callback, *args)</code></td><td>Thread-safe callback</td><td>Pushes a callback from the thread pool back into the event loop</td></tr>
|
|
1812
|
+
<tr><td><code>check_cancel()</code></td><td>Check if current coroutine was cancelled</td><td>Raises <code>CancelledError</code> if cancelled</td></tr>
|
|
1813
|
+
<tr><td><code>shutdown()</code></td><td>Graceful shutdown</td><td>Cancels all tasks, closes thread and process pools</td></tr>
|
|
1814
|
+
<tr><td><code>human_input</code></td><td>Human input manager instance</td><td>Provides <code>wait_for_input</code> and <code>provide_input</code></td></tr>
|
|
1815
|
+
</table>
|
|
1816
|
+
</div>
|
|
1817
|
+
|
|
1818
|
+
<div class="callout info">
|
|
1819
|
+
<span class="callout-icon">ℹ️</span>
|
|
1820
|
+
<div class="callout-body">Four core design principles: ① VarManager uniformly manages vars and actors — any <code>@xxx</code> is a direct get; ② The <code>@</code> symbol is always preserved, never added or removed; ③ No silent fallbacks — syntax errors, missing config, and undeclared variables always throw errors; ④ Building-block architecture — the engine only collects blocks, not bound to any prompt layout or LLM calling convention.</div>
|
|
1821
|
+
</div>
|
|
1822
|
+
</div>
|
|
1823
|
+
|
|
1824
|
+
</div><!-- /content -->
|
|
1825
|
+
</main>
|
|
1826
|
+
|
|
1827
|
+
<button id="menu-toggle" aria-label="Menu">☰</button>
|
|
1828
|
+
|
|
1829
|
+
<script>
|
|
1830
|
+
// ── Copy button ──
|
|
1831
|
+
document.querySelectorAll('.code-copy').forEach(btn => {
|
|
1832
|
+
btn.addEventListener('click', () => {
|
|
1833
|
+
const pre = btn.closest('.code-block').querySelector('pre');
|
|
1834
|
+
const text = pre.innerText;
|
|
1835
|
+
navigator.clipboard.writeText(text).then(() => {
|
|
1836
|
+
btn.textContent = 'copied!';
|
|
1837
|
+
btn.classList.add('copied');
|
|
1838
|
+
setTimeout(() => { btn.textContent = 'copy'; btn.classList.remove('copied'); }, 2000);
|
|
1839
|
+
}).catch(() => {
|
|
1840
|
+
btn.textContent = 'error';
|
|
1841
|
+
setTimeout(() => { btn.textContent = 'copy'; }, 2000);
|
|
1842
|
+
});
|
|
1843
|
+
});
|
|
1844
|
+
});
|
|
1845
|
+
|
|
1846
|
+
// ── Scroll reveal ──
|
|
1847
|
+
const revealObserver = new IntersectionObserver(entries => {
|
|
1848
|
+
entries.forEach(e => { if (e.isIntersecting) e.target.classList.add('visible'); });
|
|
1849
|
+
}, { threshold: 0.05, rootMargin: '0px 0px -30px 0px' });
|
|
1850
|
+
document.querySelectorAll('.doc-section').forEach(s => revealObserver.observe(s));
|
|
1851
|
+
|
|
1852
|
+
// ── Active TOC highlight ──
|
|
1853
|
+
const sections = document.querySelectorAll('.section-anchor');
|
|
1854
|
+
const tocLinks = document.querySelectorAll('.toc-link');
|
|
1855
|
+
|
|
1856
|
+
const tocObserver = new IntersectionObserver(entries => {
|
|
1857
|
+
entries.forEach(e => {
|
|
1858
|
+
if (e.isIntersecting) {
|
|
1859
|
+
const id = e.target.id.replace('s-', '');
|
|
1860
|
+
tocLinks.forEach(link => {
|
|
1861
|
+
link.classList.toggle('active', link.getAttribute('href') === '#s-' + id);
|
|
1862
|
+
});
|
|
1863
|
+
}
|
|
1864
|
+
});
|
|
1865
|
+
}, { rootMargin: '-80px 0px -60% 0px', threshold: 0 });
|
|
1866
|
+
sections.forEach(s => tocObserver.observe(s));
|
|
1867
|
+
|
|
1868
|
+
// ── TOC click smooth scroll ──
|
|
1869
|
+
tocLinks.forEach(link => {
|
|
1870
|
+
link.addEventListener('click', e => {
|
|
1871
|
+
e.preventDefault();
|
|
1872
|
+
const target = document.querySelector(link.getAttribute('href'));
|
|
1873
|
+
if (target) {
|
|
1874
|
+
target.scrollIntoView({ behavior: 'smooth' });
|
|
1875
|
+
if (window.innerWidth <= 768) {
|
|
1876
|
+
document.getElementById('sidebar').classList.remove('open');
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
});
|
|
1880
|
+
});
|
|
1881
|
+
|
|
1882
|
+
// ── Progress bar ──
|
|
1883
|
+
const progressBar = document.getElementById('progress-bar');
|
|
1884
|
+
window.addEventListener('scroll', () => {
|
|
1885
|
+
const scrolled = window.scrollY;
|
|
1886
|
+
const total = document.documentElement.scrollHeight - window.innerHeight;
|
|
1887
|
+
progressBar.style.width = (scrolled / total * 100) + '%';
|
|
1888
|
+
}, { passive: true });
|
|
1889
|
+
|
|
1890
|
+
// ── Mobile sidebar ──
|
|
1891
|
+
const menuToggle = document.getElementById('menu-toggle');
|
|
1892
|
+
const sidebar = document.getElementById('sidebar');
|
|
1893
|
+
menuToggle.addEventListener('click', () => sidebar.classList.toggle('open'));
|
|
1894
|
+
document.addEventListener('click', e => {
|
|
1895
|
+
if (!sidebar.contains(e.target) && !menuToggle.contains(e.target)) {
|
|
1896
|
+
sidebar.classList.remove('open');
|
|
1897
|
+
}
|
|
1898
|
+
});
|
|
1899
|
+
|
|
1900
|
+
// ── Search ──
|
|
1901
|
+
const searchInput = document.getElementById('search-input');
|
|
1902
|
+
searchInput.addEventListener('input', () => {
|
|
1903
|
+
const q = searchInput.value.trim().toLowerCase();
|
|
1904
|
+
tocLinks.forEach(link => {
|
|
1905
|
+
const text = link.textContent.toLowerCase();
|
|
1906
|
+
link.style.display = (!q || text.includes(q)) ? '' : 'none';
|
|
1907
|
+
});
|
|
1908
|
+
document.querySelectorAll('.toc-group').forEach(g => {
|
|
1909
|
+
const visibles = [...g.querySelectorAll('.toc-link')].filter(l => l.style.display !== 'none');
|
|
1910
|
+
g.style.display = visibles.length ? '' : 'none';
|
|
1911
|
+
});
|
|
1912
|
+
});
|
|
1913
|
+
|
|
1914
|
+
// ══════════════════════════════════════════
|
|
1915
|
+
// Shared animation utilities
|
|
1916
|
+
// ══════════════════════════════════════════
|
|
1917
|
+
const A = {
|
|
1918
|
+
bg: '#1f201e',
|
|
1919
|
+
border: 'rgba(255,255,255,0.07)',
|
|
1920
|
+
gold: '#c8a84b',
|
|
1921
|
+
gold2: '#a07e2e',
|
|
1922
|
+
green: '#6aaa64',
|
|
1923
|
+
blue: '#79b8d4',
|
|
1924
|
+
purple: '#c586c0',
|
|
1925
|
+
text1: '#e8e4d8',
|
|
1926
|
+
text2: '#a89e88',
|
|
1927
|
+
text3: '#5e5a52',
|
|
1928
|
+
|
|
1929
|
+
lerp(a, b, t) { return a + (b - a) * t; },
|
|
1930
|
+
clamp(v, lo, hi) { return Math.max(lo, Math.min(hi, v)); },
|
|
1931
|
+
ease(t) { return t < 0.5 ? 2*t*t : -1+(4-2*t)*t; },
|
|
1932
|
+
|
|
1933
|
+
node(ctx, x, y, w, h, label, active, color) {
|
|
1934
|
+
ctx.save();
|
|
1935
|
+
ctx.strokeStyle = active ? color : A.text3;
|
|
1936
|
+
ctx.lineWidth = active ? 1.8 : 1;
|
|
1937
|
+
ctx.globalAlpha = active ? 1 : 0.4;
|
|
1938
|
+
ctx.fillStyle = active ? 'rgba(255,255,255,0.04)' : 'transparent';
|
|
1939
|
+
const rx = 4;
|
|
1940
|
+
ctx.beginPath();
|
|
1941
|
+
ctx.moveTo(x - w/2 + rx, y - h/2);
|
|
1942
|
+
ctx.lineTo(x + w/2 - rx, y - h/2);
|
|
1943
|
+
ctx.arcTo(x + w/2, y - h/2, x + w/2, y - h/2 + rx, rx);
|
|
1944
|
+
ctx.lineTo(x + w/2, y + h/2 - rx);
|
|
1945
|
+
ctx.arcTo(x + w/2, y + h/2, x + w/2 - rx, y + h/2, rx);
|
|
1946
|
+
ctx.lineTo(x - w/2 + rx, y + h/2);
|
|
1947
|
+
ctx.arcTo(x - w/2, y + h/2, x - w/2, y + h/2 - rx, rx);
|
|
1948
|
+
ctx.lineTo(x - w/2, y - h/2 + rx);
|
|
1949
|
+
ctx.arcTo(x - w/2, y - h/2, x - w/2 + rx, y - h/2, rx);
|
|
1950
|
+
ctx.closePath();
|
|
1951
|
+
ctx.fill(); ctx.stroke();
|
|
1952
|
+
ctx.fillStyle = active ? color : A.text3;
|
|
1953
|
+
ctx.font = `${active ? 500 : 400} 11px "IBM Plex Mono", monospace`;
|
|
1954
|
+
ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
|
|
1955
|
+
ctx.fillText(label, x, y);
|
|
1956
|
+
ctx.restore();
|
|
1957
|
+
},
|
|
1958
|
+
|
|
1959
|
+
arrow(ctx, x1, y1, x2, y2, color, alpha) {
|
|
1960
|
+
ctx.save();
|
|
1961
|
+
ctx.strokeStyle = color; ctx.lineWidth = 1.2; ctx.globalAlpha = alpha || 0.35;
|
|
1962
|
+
ctx.beginPath(); ctx.moveTo(x1, y1); ctx.lineTo(x2, y2); ctx.stroke();
|
|
1963
|
+
const angle = Math.atan2(y2 - y1, x2 - x1);
|
|
1964
|
+
const al = 7, aw = 3;
|
|
1965
|
+
ctx.fillStyle = color; ctx.globalAlpha = alpha || 0.35;
|
|
1966
|
+
ctx.beginPath();
|
|
1967
|
+
ctx.moveTo(x2, y2);
|
|
1968
|
+
ctx.lineTo(x2 - al * Math.cos(angle - aw), y2 - al * Math.sin(angle - aw));
|
|
1969
|
+
ctx.lineTo(x2 - al * Math.cos(angle + aw), y2 - al * Math.sin(angle + aw));
|
|
1970
|
+
ctx.closePath(); ctx.fill();
|
|
1971
|
+
ctx.restore();
|
|
1972
|
+
},
|
|
1973
|
+
|
|
1974
|
+
packet(ctx, x, y, color) {
|
|
1975
|
+
ctx.save();
|
|
1976
|
+
ctx.fillStyle = color; ctx.globalAlpha = 0.85;
|
|
1977
|
+
ctx.shadowColor = color; ctx.shadowBlur = 8;
|
|
1978
|
+
ctx.beginPath(); ctx.arc(x, y, 5, 0, Math.PI * 2); ctx.fill();
|
|
1979
|
+
ctx.restore();
|
|
1980
|
+
}
|
|
1981
|
+
};
|
|
1982
|
+
|
|
1983
|
+
// ══════════════════════════════════════════
|
|
1984
|
+
// FORK animation
|
|
1985
|
+
// ══════════════════════════════════════════
|
|
1986
|
+
const forkAnim = (() => {
|
|
1987
|
+
const canvas = document.getElementById('canvas-fork');
|
|
1988
|
+
if (!canvas) return { restart() {} };
|
|
1989
|
+
const ctx = canvas.getContext('2d');
|
|
1990
|
+
const W = canvas.width, H = canvas.height;
|
|
1991
|
+
let startTime = null, raf = null;
|
|
1992
|
+
const DUR = 4000;
|
|
1993
|
+
|
|
1994
|
+
const nd = {
|
|
1995
|
+
A: { x: 80, y: H/2 },
|
|
1996
|
+
B: { x: 220, y: H/2 },
|
|
1997
|
+
fork: { x: 320, y: H/2 },
|
|
1998
|
+
vis: { x: 490, y: H/2 - 60 },
|
|
1999
|
+
solo: { x: 490, y: H/2 + 60 },
|
|
2000
|
+
end: { x: 650, y: H/2 },
|
|
2001
|
+
};
|
|
2002
|
+
|
|
2003
|
+
function draw(now) {
|
|
2004
|
+
if (!startTime) startTime = now;
|
|
2005
|
+
const t = Math.min((now - startTime) / DUR, 1);
|
|
2006
|
+
ctx.clearRect(0, 0, W, H);
|
|
2007
|
+
|
|
2008
|
+
const phase1 = A.clamp(t / 0.3, 0, 1);
|
|
2009
|
+
const phase2 = A.clamp((t - 0.3) / 0.25, 0, 1);
|
|
2010
|
+
const phase3 = A.clamp((t - 0.55) / 0.35, 0, 1);
|
|
2011
|
+
const phase4 = A.clamp((t - 0.82) / 0.18, 0, 1);
|
|
2012
|
+
|
|
2013
|
+
A.arrow(ctx, nd.A.x+28, nd.A.y, nd.B.x-28, nd.B.y, A.text3, 0.3);
|
|
2014
|
+
A.arrow(ctx, nd.B.x+24, nd.B.y, nd.fork.x-8, nd.fork.y, A.text3, 0.3);
|
|
2015
|
+
A.arrow(ctx, nd.fork.x+8, nd.fork.y, nd.vis.x-32, nd.vis.y, A.blue, 0.25);
|
|
2016
|
+
A.arrow(ctx, nd.fork.x+8, nd.fork.y, nd.solo.x-32, nd.solo.y, A.purple, 0.25);
|
|
2017
|
+
A.arrow(ctx, nd.vis.x+32, nd.vis.y, nd.end.x-28, nd.end.y, A.blue, 0.2);
|
|
2018
|
+
A.arrow(ctx, nd.solo.x+32, nd.solo.y, nd.end.x-28, nd.end.y, A.purple, 0.2);
|
|
2019
|
+
|
|
2020
|
+
A.node(ctx, nd.A.x, nd.A.y, 48, 28, '[A]', t > 0.05, A.text3);
|
|
2021
|
+
A.node(ctx, nd.B.x, nd.B.y, 48, 28, '[B]', t > 0.15, A.text3);
|
|
2022
|
+
A.node(ctx, nd.fork.x, nd.fork.y, 40, 26, 'fork', t > 0.28, A.gold);
|
|
2023
|
+
A.node(ctx, nd.vis.x, nd.vis.y, 72, 26, '[visit]', phase2 > 0.3, A.blue);
|
|
2024
|
+
A.node(ctx, nd.solo.x, nd.solo.y, 64, 26, '[solo]', phase2 > 0.3, A.purple);
|
|
2025
|
+
A.node(ctx, nd.end.x, nd.end.y, 56, 28, '[END]', phase4 > 0.5, A.gold);
|
|
2026
|
+
|
|
2027
|
+
if (phase1 > 0 && phase1 < 1) {
|
|
2028
|
+
const px = A.lerp(nd.A.x + 28, nd.B.x - 28, A.ease(phase1));
|
|
2029
|
+
A.packet(ctx, px, nd.A.y, A.gold);
|
|
2030
|
+
}
|
|
2031
|
+
if (phase2 > 0 && phase2 < 1) {
|
|
2032
|
+
const px1 = A.lerp(nd.fork.x + 8, nd.vis.x - 32, A.ease(phase2));
|
|
2033
|
+
const py1 = A.lerp(nd.fork.y, nd.vis.y, A.ease(phase2));
|
|
2034
|
+
A.packet(ctx, px1, py1, A.blue);
|
|
2035
|
+
const px2 = A.lerp(nd.fork.x + 8, nd.solo.x - 32, A.ease(phase2));
|
|
2036
|
+
const py2 = A.lerp(nd.fork.y, nd.solo.y, A.ease(phase2));
|
|
2037
|
+
A.packet(ctx, px2, py2, A.purple);
|
|
2038
|
+
}
|
|
2039
|
+
if (phase3 > 0 && phase3 < 1) {
|
|
2040
|
+
const e = A.ease(phase3);
|
|
2041
|
+
A.packet(ctx, A.lerp(nd.vis.x-24, nd.vis.x+24, e), nd.vis.y, A.blue);
|
|
2042
|
+
A.packet(ctx, A.lerp(nd.solo.x-24, nd.solo.x+24, e), nd.solo.y, A.purple);
|
|
2043
|
+
}
|
|
2044
|
+
if (phase4 > 0) {
|
|
2045
|
+
const e = A.ease(A.clamp(phase4, 0, 1));
|
|
2046
|
+
A.packet(ctx, A.lerp(nd.vis.x+32, nd.end.x-28, e), A.lerp(nd.vis.y, nd.end.y, e), A.blue);
|
|
2047
|
+
A.packet(ctx, A.lerp(nd.solo.x+32, nd.end.x-28, e), A.lerp(nd.solo.y, nd.end.y, e), A.purple);
|
|
2048
|
+
}
|
|
2049
|
+
|
|
2050
|
+
ctx.save();
|
|
2051
|
+
ctx.fillStyle = A.gold; ctx.globalAlpha = 0.5;
|
|
2052
|
+
ctx.font = '10px "IBM Plex Mono", monospace';
|
|
2053
|
+
ctx.textAlign = 'center';
|
|
2054
|
+
ctx.fillText('fork', nd.fork.x, nd.fork.y - 20);
|
|
2055
|
+
ctx.restore();
|
|
2056
|
+
|
|
2057
|
+
if (t < 1) raf = requestAnimationFrame(draw);
|
|
2058
|
+
}
|
|
2059
|
+
|
|
2060
|
+
function start() {
|
|
2061
|
+
if (raf) cancelAnimationFrame(raf);
|
|
2062
|
+
startTime = null; raf = requestAnimationFrame(draw);
|
|
2063
|
+
}
|
|
2064
|
+
|
|
2065
|
+
const obs = new IntersectionObserver(entries => {
|
|
2066
|
+
if (entries[0].isIntersecting) { start(); obs.disconnect(); }
|
|
2067
|
+
}, { threshold: 0.3 });
|
|
2068
|
+
obs.observe(canvas);
|
|
2069
|
+
return { restart: start };
|
|
2070
|
+
})();
|
|
2071
|
+
|
|
2072
|
+
// ══════════════════════════════════════════
|
|
2073
|
+
// FOR animation
|
|
2074
|
+
// ══════════════════════════════════════════
|
|
2075
|
+
const forAnim = (() => {
|
|
2076
|
+
const canvas = document.getElementById('canvas-for');
|
|
2077
|
+
if (!canvas) return { restart() {} };
|
|
2078
|
+
const ctx = canvas.getContext('2d');
|
|
2079
|
+
const W = canvas.width, H = canvas.height;
|
|
2080
|
+
let startTime = null, raf = null;
|
|
2081
|
+
const ITEMS = ['@p1','@p2','@p3'];
|
|
2082
|
+
const DUR = 4200;
|
|
2083
|
+
|
|
2084
|
+
const nd = {
|
|
2085
|
+
pre: { x:60, y:H/2, label:'[B]' },
|
|
2086
|
+
c: { x:220, y:H/2, label:'[C]' },
|
|
2087
|
+
d: { x:370, y:H/2, label:'[D]' },
|
|
2088
|
+
end: { x:560, y:H/2, label:'[END]' },
|
|
2089
|
+
};
|
|
2090
|
+
|
|
2091
|
+
function draw(now) {
|
|
2092
|
+
if (!startTime) startTime = now;
|
|
2093
|
+
const elapsed = now - startTime;
|
|
2094
|
+
const t = Math.min(elapsed / DUR, 1);
|
|
2095
|
+
ctx.clearRect(0, 0, W, H);
|
|
2096
|
+
|
|
2097
|
+
A.arrow(ctx, nd.pre.x+28, nd.pre.y, nd.c.x-28, nd.c.y, A.text3, 0.35);
|
|
2098
|
+
A.arrow(ctx, nd.c.x+28, nd.c.y, nd.d.x-28, nd.d.y, A.text3, 0.35);
|
|
2099
|
+
A.arrow(ctx, nd.d.x+28, nd.d.y, nd.end.x-40, nd.end.y, A.text3, 0.35);
|
|
2100
|
+
|
|
2101
|
+
ctx.save();
|
|
2102
|
+
ctx.setLineDash([3,4]);
|
|
2103
|
+
ctx.strokeStyle = A.gold2; ctx.lineWidth = 1.2; ctx.globalAlpha = 0.45;
|
|
2104
|
+
ctx.beginPath();
|
|
2105
|
+
ctx.moveTo(nd.d.x, nd.d.y+14);
|
|
2106
|
+
ctx.bezierCurveTo(nd.d.x, nd.d.y+48, nd.c.x, nd.d.y+48, nd.c.x, nd.c.y+14);
|
|
2107
|
+
ctx.stroke();
|
|
2108
|
+
ctx.setLineDash([]);
|
|
2109
|
+
ctx.restore();
|
|
2110
|
+
|
|
2111
|
+
A.node(ctx, nd.pre.x, nd.pre.y, 48, 28, '[B]', true, A.text3);
|
|
2112
|
+
A.node(ctx, nd.c.x, nd.c.y, 48, 28, '[C]', false, A.text3);
|
|
2113
|
+
A.node(ctx, nd.d.x, nd.d.y, 48, 28, '[D]', false, A.text3);
|
|
2114
|
+
A.node(ctx, nd.end.x, nd.end.y, 56, 28, '[END]', false, A.text3);
|
|
2115
|
+
|
|
2116
|
+
const iterDur = 0.26;
|
|
2117
|
+
const iterStart = 0.08;
|
|
2118
|
+
ITEMS.forEach((item, i) => {
|
|
2119
|
+
const it0 = iterStart + i * iterDur;
|
|
2120
|
+
if (t < it0) return;
|
|
2121
|
+
const it = A.clamp((t - it0) / iterDur, 0, 1);
|
|
2122
|
+
|
|
2123
|
+
const atC = it < 0.45;
|
|
2124
|
+
const atD = it >= 0.45 && it < 0.85;
|
|
2125
|
+
if (atC) A.node(ctx, nd.c.x, nd.c.y, 48, 28, '[C]', true, A.blue);
|
|
2126
|
+
if (atD) A.node(ctx, nd.d.x, nd.d.y, 48, 28, '[D]', true, A.blue);
|
|
2127
|
+
|
|
2128
|
+
let px, py;
|
|
2129
|
+
if (it < 0.45) {
|
|
2130
|
+
const pt = it / 0.45;
|
|
2131
|
+
px = A.lerp(nd.c.x-24, nd.c.x+24, pt);
|
|
2132
|
+
py = nd.c.y;
|
|
2133
|
+
} else if (it < 0.85) {
|
|
2134
|
+
const pt = (it-0.45)/0.4;
|
|
2135
|
+
px = A.lerp(nd.d.x-24, nd.d.x+24, pt);
|
|
2136
|
+
py = nd.d.y;
|
|
2137
|
+
} else {
|
|
2138
|
+
const isLast = i === ITEMS.length-1;
|
|
2139
|
+
if (isLast) {
|
|
2140
|
+
const pt = (it-0.85)/0.15;
|
|
2141
|
+
px = A.lerp(nd.d.x+24, nd.end.x-28, pt);
|
|
2142
|
+
py = nd.end.y;
|
|
2143
|
+
} else {
|
|
2144
|
+
const pt = (it-0.85)/0.15;
|
|
2145
|
+
px = A.lerp(nd.d.x, nd.c.x, pt);
|
|
2146
|
+
py = nd.d.y + Math.sin(pt*Math.PI)*34;
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
A.packet(ctx, px, py, A.blue);
|
|
2150
|
+
|
|
2151
|
+
ctx.save();
|
|
2152
|
+
ctx.fillStyle = A.text2; ctx.globalAlpha = 0.8;
|
|
2153
|
+
ctx.font = '10px "IBM Plex Mono", monospace';
|
|
2154
|
+
ctx.textAlign = 'left';
|
|
2155
|
+
ctx.fillText(`iter ${i+1}: ${item}`, 10, 18 + i*16);
|
|
2156
|
+
ctx.restore();
|
|
2157
|
+
});
|
|
2158
|
+
|
|
2159
|
+
if (t > iterStart + ITEMS.length * iterDur) {
|
|
2160
|
+
A.node(ctx, nd.end.x, nd.end.y, 56, 28, '[END]', true, A.gold);
|
|
2161
|
+
ctx.save();
|
|
2162
|
+
ctx.fillStyle = A.gold; ctx.globalAlpha = 0.7;
|
|
2163
|
+
ctx.font = '11px "IBM Plex Mono", monospace';
|
|
2164
|
+
ctx.textAlign = 'center';
|
|
2165
|
+
ctx.fillText('loop done →', nd.end.x, nd.end.y + 28);
|
|
2166
|
+
ctx.restore();
|
|
2167
|
+
}
|
|
2168
|
+
|
|
2169
|
+
if (t < 1) raf = requestAnimationFrame(draw);
|
|
2170
|
+
}
|
|
2171
|
+
|
|
2172
|
+
function start() {
|
|
2173
|
+
if (raf) cancelAnimationFrame(raf);
|
|
2174
|
+
startTime = null;
|
|
2175
|
+
raf = requestAnimationFrame(draw);
|
|
2176
|
+
}
|
|
2177
|
+
const obs = new IntersectionObserver(entries => {
|
|
2178
|
+
if (entries[0].isIntersecting) { start(); obs.disconnect(); }
|
|
2179
|
+
}, { threshold: 0.3 });
|
|
2180
|
+
obs.observe(canvas);
|
|
2181
|
+
return { restart: start };
|
|
2182
|
+
})();
|
|
2183
|
+
|
|
2184
|
+
// ══════════════════════════════════════════
|
|
2185
|
+
// PAR animation
|
|
2186
|
+
// ══════════════════════════════════════════
|
|
2187
|
+
const parAnim = (() => {
|
|
2188
|
+
const canvas = document.getElementById('canvas-par');
|
|
2189
|
+
if (!canvas) return { restart() {} };
|
|
2190
|
+
const ctx = canvas.getContext('2d');
|
|
2191
|
+
const W = canvas.width, H = canvas.height;
|
|
2192
|
+
let startTime = null, raf = null;
|
|
2193
|
+
const DUR = 4000;
|
|
2194
|
+
|
|
2195
|
+
const WORKERS = [
|
|
2196
|
+
{ label:'@coder1', color: A.blue },
|
|
2197
|
+
{ label:'@coder2', color: A.green },
|
|
2198
|
+
{ label:'@coder3', color: A.purple },
|
|
2199
|
+
];
|
|
2200
|
+
const rowH = H / (WORKERS.length + 1);
|
|
2201
|
+
const preX = 70, writeX = 240, tryX = 390, endX = 560;
|
|
2202
|
+
|
|
2203
|
+
function draw(now) {
|
|
2204
|
+
if (!startTime) startTime = now;
|
|
2205
|
+
const t = Math.min((now - startTime) / DUR, 1);
|
|
2206
|
+
ctx.clearRect(0, 0, W, H);
|
|
2207
|
+
|
|
2208
|
+
const preY = H/2;
|
|
2209
|
+
A.node(ctx, preX, preY, 64, 28, '[START]', t>0.05, A.gold);
|
|
2210
|
+
|
|
2211
|
+
WORKERS.forEach((w, i) => {
|
|
2212
|
+
const y = (i+1) * rowH;
|
|
2213
|
+
const alpha = A.clamp((t-0.15)/0.15, 0, 1);
|
|
2214
|
+
A.arrow(ctx, preX+32, preY, writeX-32, y, w.color, alpha*0.35);
|
|
2215
|
+
});
|
|
2216
|
+
|
|
2217
|
+
WORKERS.forEach((w, i) => {
|
|
2218
|
+
const y = (i+1) * rowH;
|
|
2219
|
+
const lt = A.clamp((t - 0.22) / 0.65, 0, 1);
|
|
2220
|
+
|
|
2221
|
+
A.arrow(ctx, writeX+32, y, tryX-32, y, A.text3, 0.25);
|
|
2222
|
+
|
|
2223
|
+
const atWrite = lt > 0 && lt < 0.5;
|
|
2224
|
+
const atTry = lt >= 0.5 && lt < 0.95;
|
|
2225
|
+
const done = lt >= 0.95;
|
|
2226
|
+
A.node(ctx, writeX, y, 64, 26, 'write', atWrite, w.color);
|
|
2227
|
+
A.node(ctx, tryX, y, 64, 26, 'try', atTry, w.color);
|
|
2228
|
+
|
|
2229
|
+
if (lt > 0 && lt < 1) {
|
|
2230
|
+
let px, py = y;
|
|
2231
|
+
if (lt < 0.5) {
|
|
2232
|
+
px = A.lerp(writeX-32, writeX+32, lt/0.5);
|
|
2233
|
+
} else {
|
|
2234
|
+
px = A.lerp(tryX-32, tryX+32, (lt-0.5)/0.45);
|
|
2235
|
+
}
|
|
2236
|
+
A.packet(ctx, px, py, w.color);
|
|
2237
|
+
}
|
|
2238
|
+
|
|
2239
|
+
ctx.save();
|
|
2240
|
+
ctx.fillStyle = w.color; ctx.globalAlpha = 0.75;
|
|
2241
|
+
ctx.font = '10px "IBM Plex Mono", monospace';
|
|
2242
|
+
ctx.textAlign = 'right';
|
|
2243
|
+
ctx.fillText(w.label, writeX-36, y+1);
|
|
2244
|
+
ctx.restore();
|
|
2245
|
+
|
|
2246
|
+
if (done) {
|
|
2247
|
+
const pt = A.clamp((lt-0.95)/0.05, 0, 1);
|
|
2248
|
+
A.arrow(ctx, tryX+32, y, endX-28, preY, w.color, pt*0.5);
|
|
2249
|
+
}
|
|
2250
|
+
});
|
|
2251
|
+
|
|
2252
|
+
const allDone = A.clamp((t-0.9)/0.1, 0, 1);
|
|
2253
|
+
A.node(ctx, endX, preY, 56, 28, '[D]', allDone>0.5, A.gold);
|
|
2254
|
+
if (allDone > 0.5) {
|
|
2255
|
+
ctx.save();
|
|
2256
|
+
ctx.fillStyle = A.gold; ctx.globalAlpha = allDone * 0.7;
|
|
2257
|
+
ctx.font = '10px "IBM Plex Mono", monospace';
|
|
2258
|
+
ctx.textAlign = 'center';
|
|
2259
|
+
ctx.fillText('all merged', endX, preY+26);
|
|
2260
|
+
ctx.restore();
|
|
2261
|
+
}
|
|
2262
|
+
|
|
2263
|
+
if (t < 1) raf = requestAnimationFrame(draw);
|
|
2264
|
+
}
|
|
2265
|
+
|
|
2266
|
+
function start() {
|
|
2267
|
+
if (raf) cancelAnimationFrame(raf);
|
|
2268
|
+
startTime = null;
|
|
2269
|
+
raf = requestAnimationFrame(draw);
|
|
2270
|
+
}
|
|
2271
|
+
const obs = new IntersectionObserver(entries => {
|
|
2272
|
+
if (entries[0].isIntersecting) { start(); obs.disconnect(); }
|
|
2273
|
+
}, { threshold: 0.3 });
|
|
2274
|
+
obs.observe(canvas);
|
|
2275
|
+
return { restart: start };
|
|
2276
|
+
})();
|
|
2277
|
+
</script>
|
|
2278
|
+
</body>
|
|
2279
|
+
</html>
|