@senpi/runtime 3.0.9-dev.20260710204324 → 3.0.9-dev.feat-strategy-compos.20260716013009

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.
Files changed (94) hide show
  1. package/dist/cli/composer-commands.d.ts +37 -0
  2. package/dist/cli/composer-commands.d.ts.map +1 -0
  3. package/dist/cli/composer-commands.js +287 -0
  4. package/dist/cli/composer-commands.js.map +1 -0
  5. package/dist/cli/senpi-commands.d.ts.map +1 -1
  6. package/dist/cli/senpi-commands.js +2 -0
  7. package/dist/cli/senpi-commands.js.map +1 -1
  8. package/dist/cli/validate-runtime-config.mjs +124 -0
  9. package/dist/composer/AUTHORING.md +233 -0
  10. package/dist/composer/__init__.py +29 -0
  11. package/dist/composer/authoring/__init__.py +49 -0
  12. package/dist/composer/authoring/answers.py +226 -0
  13. package/dist/composer/authoring/archetypes/__init__.py +25 -0
  14. package/dist/composer/authoring/archetypes/_common.py +218 -0
  15. package/dist/composer/authoring/archetypes/classifier.py +109 -0
  16. package/dist/composer/authoring/archetypes/skeleton.py +54 -0
  17. package/dist/composer/authoring/archetypes/thesis_fund.py +103 -0
  18. package/dist/composer/authoring/archetypes/trend_momentum.py +104 -0
  19. package/dist/composer/authoring/builder.py +191 -0
  20. package/dist/composer/authoring/emit.py +264 -0
  21. package/dist/composer/authoring/gaps.py +115 -0
  22. package/dist/composer/authoring/generate.py +131 -0
  23. package/dist/composer/authoring/presets.py +168 -0
  24. package/dist/composer/authoring/runtime_emit.py +266 -0
  25. package/dist/composer/authoring/strategy_manifest.py +94 -0
  26. package/dist/composer/cli.py +355 -0
  27. package/dist/composer/compiler/__init__.py +22 -0
  28. package/dist/composer/compiler/compile.py +550 -0
  29. package/dist/composer/examples/breakout_swing.graph.yaml +121 -0
  30. package/dist/composer/examples/conviction_scorer.graph.yaml +216 -0
  31. package/dist/composer/examples/macro_thesis_basket.graph.yaml +247 -0
  32. package/dist/composer/examples/pre_listing_classifier.graph.yaml +204 -0
  33. package/dist/composer/examples/trend_momentum_majors.graph.yaml +133 -0
  34. package/dist/composer/generated/README.md +22 -0
  35. package/dist/composer/generated/catalog.md +84 -0
  36. package/dist/composer/generated/describe.md +703 -0
  37. package/dist/composer/generated/graph.schema.json +1203 -0
  38. package/dist/composer/primitives/__init__.py +239 -0
  39. package/dist/composer/primitives/_candles.py +76 -0
  40. package/dist/composer/primitives/adapter.py +120 -0
  41. package/dist/composer/primitives/emitters.py +142 -0
  42. package/dist/composer/primitives/filters.py +71 -0
  43. package/dist/composer/primitives/indicators.py +203 -0
  44. package/dist/composer/primitives/rankers.py +40 -0
  45. package/dist/composer/primitives/scorers.py +100 -0
  46. package/dist/composer/primitives/sources.py +405 -0
  47. package/dist/composer/primitives/stateful.py +52 -0
  48. package/dist/composer/pure_fn/__init__.py +34 -0
  49. package/dist/composer/pure_fn/checks.py +39 -0
  50. package/dist/composer/pure_fn/models.py +177 -0
  51. package/dist/composer/pure_fn/purity.py +311 -0
  52. package/dist/composer/pure_fn/runtests.py +155 -0
  53. package/dist/composer/registry/__init__.py +40 -0
  54. package/dist/composer/registry/generate.py +422 -0
  55. package/dist/composer/registry/models.py +331 -0
  56. package/dist/composer/registry/nodes.py +673 -0
  57. package/dist/composer/requirements.txt +21 -0
  58. package/dist/composer/templates/__init__.py +13 -0
  59. package/dist/composer/templates/scan.py.j2 +31 -0
  60. package/dist/composer/validator/__init__.py +29 -0
  61. package/dist/composer/validator/desugar.py +133 -0
  62. package/dist/composer/validator/errors.py +191 -0
  63. package/dist/composer/validator/graph_checks.py +348 -0
  64. package/dist/composer/validator/loader.py +110 -0
  65. package/dist/composer/validator/schema_checks.py +147 -0
  66. package/dist/composer/validator/validate.py +86 -0
  67. package/dist/composer/verbs/__init__.py +33 -0
  68. package/dist/composer/verbs/check.py +193 -0
  69. package/dist/composer/verbs/deploy.py +223 -0
  70. package/dist/composer/verbs/docs.py +30 -0
  71. package/dist/composer/verbs/runtime_validate.py +262 -0
  72. package/dist/composer/verbs/smoke.py +115 -0
  73. package/dist/composer/verbs/status.py +205 -0
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +2 -9
  76. package/dist/index.js.map +1 -1
  77. package/dist/runtime-api/config.d.ts +2 -2
  78. package/dist/runtime-api/config.js +4 -4
  79. package/dist/runtime-api/config.js.map +1 -1
  80. package/dist/runtime-api/handlers/ingest-signals.d.ts +3 -5
  81. package/dist/runtime-api/handlers/ingest-signals.d.ts.map +1 -1
  82. package/dist/runtime-api/handlers/ingest-signals.js +5 -14
  83. package/dist/runtime-api/handlers/ingest-signals.js.map +1 -1
  84. package/dist/runtime-api/intake/intake-mount.d.ts.map +1 -1
  85. package/dist/runtime-api/intake/intake-mount.js +2 -8
  86. package/dist/runtime-api/intake/intake-mount.js.map +1 -1
  87. package/dist/skills-manager/manifest.js +1 -1
  88. package/dist/skills-manager/manifest.js.map +1 -1
  89. package/dist/skills-manager/skills-manifest.json +1 -1
  90. package/package.json +4 -2
  91. package/dist/runtime-api/intake/ingest-mutex.d.ts +0 -16
  92. package/dist/runtime-api/intake/ingest-mutex.d.ts.map +0 -1
  93. package/dist/runtime-api/intake/ingest-mutex.js +0 -18
  94. package/dist/runtime-api/intake/ingest-mutex.js.map +0 -1
@@ -0,0 +1,703 @@
1
+ # Strategy Composer — Node Reference
2
+
3
+ Schema version: 1. Generated from composer/registry/nodes.py — do not edit by hand.
4
+
5
+ ## asset_trading_limits_fetch (source)
6
+
7
+ strategy_get_asset_trading_limits fanned out per-asset over the wired universe (one single-asset MCP call each, like candles_fetch), reduced to a max_leverage feature_map. Distinct from instrument_list's board-wide max_leverage in that it is the account-and-venue-specific tradeable limit.
8
+
9
+ Inputs:
10
+ - `assets`: asset_list — Universe to read per-asset limits for; omit to use the base whitelist. [optional]
11
+
12
+ Outputs:
13
+ - `max_leverage`: feature_map — Per-asset venue max leverage.
14
+
15
+ Params:
16
+ - `dex`: str (default: '') — Venue filter (e.g. 'xyz'); empty means the default venue.
17
+
18
+ Cost: One strategy_get_asset_trading_limits MCP call per asset per tick.
19
+
20
+ Example:
21
+ ```yaml
22
+ node: asset_trading_limits_fetch
23
+ with:
24
+ dex: "xyz"
25
+ ```
26
+
27
+ ## candles_fetch (source)
28
+
29
+ Reads market_get_asset_data for each asset across one or more intervals. The universe comes from the wired `assets` input; when no input is wired the static `whitelist` param supplies it (stag's fixed BTC/ETH/SOL/HYPE). Optionally pulls funding and asset_context (markPx/prevDayPx) alongside candles.
30
+
31
+ Inputs:
32
+ - `assets`: asset_list — Universe to fetch; omit to use the `whitelist` param. [optional]
33
+
34
+ Outputs:
35
+ - `candles`: candles — Per-asset OHLCV keyed by interval.
36
+
37
+ Params:
38
+ - `whitelist`: list[str] (default: []) — Static universe used when no `assets` input is wired (stag whitelist).
39
+ - `intervals`: list[str] (default: [4h]) — Candle intervals to fetch (stag 4h; hawk 1h+4h; bison 15m/1h/4h).
40
+ - `include_funding`: bool (default: False) — Also fetch funding series (bison funding-alignment).
41
+ - `include_asset_context`: bool (default: False) — Also fetch markPx/prevDayPx asset_context (thesis-fund 24h return).
42
+
43
+ Cost: One market_get_asset_data MCP call per asset x interval per tick.
44
+
45
+ Example:
46
+ ```yaml
47
+ node: candles_fetch
48
+ with:
49
+ whitelist: ["BTC", "ETH", "SOL", "HYPE"]
50
+ intervals: ["4h"]
51
+ ```
52
+
53
+ ## clearinghouse_state (source)
54
+
55
+ strategy_get_clearinghouse_state for the strategy wallet. Returns the dual-DEX max() account equity and the held-asset set. The 'margin-in-use but empty positions' read-sanity skip (hawk) is built in — no param exposes it.
56
+
57
+ Inputs:
58
+ - (none)
59
+
60
+ Outputs:
61
+ - `held`: asset_list — Assets with an open position (for held-exclusion).
62
+ - `equity`: scalar — Dual-DEX max() account value.
63
+
64
+ Params:
65
+ - (none)
66
+
67
+ Cost: One strategy_get_clearinghouse_state MCP call per tick.
68
+
69
+ Example:
70
+ ```yaml
71
+ node: clearinghouse_state
72
+ ```
73
+
74
+ ## instrument_list (source)
75
+
76
+ market_list_instruments, used two ways in the corpus: venue-meta lookup (max_leverage, is_delisted — thesis-fund) and, filtered through a predicate, dynamic-universe discovery (magpie).
77
+
78
+ Inputs:
79
+ - (none)
80
+
81
+ Outputs:
82
+ - `instruments`: asset_list — Live instruments with venue metadata.
83
+
84
+ Params:
85
+ - `dex`: str (default: '') — Venue filter (e.g. 'xyz'); empty means all venues (magpie uses 'xyz').
86
+
87
+ Cost: One market_list_instruments MCP call per tick.
88
+
89
+ Example:
90
+ ```yaml
91
+ node: instrument_list
92
+ with:
93
+ dex: "xyz"
94
+ ```
95
+
96
+ ## market_prices_fetch (source)
97
+
98
+ market_get_prices for a venue, reduced to a per-asset price feature_map. The response is filtered to the wired `assets` universe (unwired = the base whitelist) and keyed as wired so it JOINS the candle/indicator feature_maps on one asset key. A live price read distinct from the candle close (no candle history), useful as a spot reference for a pure_fn.
99
+
100
+ Inputs:
101
+ - `assets`: asset_list — Universe to key prices by; omit to use the base whitelist. [optional]
102
+
103
+ Outputs:
104
+ - `prices`: feature_map — Per-asset latest price.
105
+
106
+ Params:
107
+ - `dex`: str (default: '') — Venue filter (e.g. 'xyz'); empty means the default venue.
108
+
109
+ Cost: One market_get_prices MCP call per tick (all prices for the venue).
110
+
111
+ Example:
112
+ ```yaml
113
+ node: market_prices_fetch
114
+ with:
115
+ dex: "xyz"
116
+ ```
117
+
118
+ ## open_orders_fetch (source)
119
+
120
+ strategy_get_open_orders for the strategy wallet, reduced to a record_list of order rows (order_id/coin/side/size/price/order_type/status/timestamp). A record_list (not asset-keyed) because multiple orders can rest on one coin; the consumer is a pure_fn reading the order fields.
121
+
122
+ Inputs:
123
+ - (none)
124
+
125
+ Outputs:
126
+ - `orders`: record_list — Open-order records.
127
+
128
+ Params:
129
+ - (none)
130
+
131
+ Cost: One strategy_get_open_orders MCP call per tick.
132
+
133
+ Example:
134
+ ```yaml
135
+ node: open_orders_fetch
136
+ ```
137
+
138
+ ## own_return_24h (source)
139
+
140
+ Derives a 24h percent return per asset from the asset_context (markPx/prevDayPx) carried on candles_fetch. thesis-fund consumes this as a distinct momentum feature; kept a source per the recon (it is a market read, not a candle transform).
141
+
142
+ Inputs:
143
+ - `candles`: candles — Candles carrying asset_context markPx/prevDayPx.
144
+
145
+ Outputs:
146
+ - `return_24h`: feature_map — Per-asset 24h percent return.
147
+
148
+ Params:
149
+ - (none)
150
+
151
+ Cost: Derived from candles asset_context; no extra MCP call.
152
+
153
+ Example:
154
+ ```yaml
155
+ node: own_return_24h
156
+ ```
157
+
158
+ ## sm_lean (source)
159
+
160
+ leaderboard_get_markets per asset, reduced to a net long/short tilt in [0,1]. The agreement band is a PARAMETER, not a new node per strategy (stag 0.60, hawk 0.55, bison 0.58) — one primitive, three thresholds.
161
+
162
+ Inputs:
163
+ - `assets`: asset_list — Assets to read leaderboard lean for. [optional]
164
+
165
+ Outputs:
166
+ - `lean`: feature_map — Per-asset SM tilt in [0,1] plus alignment flag.
167
+
168
+ Params:
169
+ - `agree_threshold`: float (default: 0.55) [0.0..1.0] — Fraction of aligned SM required to count as agreeing (corpus 0.55-0.60).
170
+
171
+ Cost: One leaderboard_get_markets MCP call per asset per tick.
172
+
173
+ Example:
174
+ ```yaml
175
+ node: sm_lean
176
+ with:
177
+ agree_threshold: 0.6
178
+ ```
179
+
180
+ ## strategy_list_fetch (source)
181
+
182
+ strategy_list, reduced to a record_list of strategy metadata (id/wallet/trader/status/strategy_type/name/created_at/total_funded). NOT asset-keyed — a record_list, whose only consumer is a pure_fn reading the record fields. Optionally filtered by status / strategy_type.
183
+
184
+ Inputs:
185
+ - (none)
186
+
187
+ Outputs:
188
+ - `strategies`: record_list — Strategy-metadata records.
189
+
190
+ Params:
191
+ - `status`: str (default: '') — Filter by strategy status (e.g. 'ACTIVE'); empty means all.
192
+ - `strategy_type`: str (default: '') — Filter by strategy type; empty means all.
193
+
194
+ Cost: One strategy_list MCP call per tick.
195
+
196
+ Example:
197
+ ```yaml
198
+ node: strategy_list_fetch
199
+ with:
200
+ status: "ACTIVE"
201
+ ```
202
+
203
+ ## strategy_pnl_snapshot (source)
204
+
205
+ strategy_get_pnl_and_account_value_history for the strategy wallet, decomposed into three account-level scalars from today_snapshot (today_pnl, today_account_value, today_drawdown). The nested multi-period history_by_period is NOT exposed (it would need a record_list; deferred until a consumer needs it).
206
+
207
+ Inputs:
208
+ - (none)
209
+
210
+ Outputs:
211
+ - `today_pnl`: scalar — Today's realized+unrealized PnL.
212
+ - `today_account_value`: scalar — Today's account value.
213
+ - `today_drawdown`: scalar — Today's drawdown.
214
+
215
+ Params:
216
+ - `period`: str (default: '') — History period hint passed through to the MCP call; empty = default.
217
+ - `drawdown_reset_on_day_rollover`: bool (default: False) — Reset drawdown at the day boundary (passed through to the MCP call).
218
+
219
+ Cost: One strategy_get_pnl_and_account_value_history MCP call per tick.
220
+
221
+ Example:
222
+ ```yaml
223
+ node: strategy_pnl_snapshot
224
+ ```
225
+
226
+ ## trader_history_fetch (source)
227
+
228
+ discovery_get_trader_history for a given trader, reduced to a record_list of closed-position rows (coin/dex/type/entry_px/exit_px/szi/realized_pnl/total_fees/close_time/open_time; times are Unix SECONDS). Enables a fade/follow-this-trader's-realized-track-record edge in a pure_fn.
229
+
230
+ Inputs:
231
+ - (none)
232
+
233
+ Outputs:
234
+ - `closed_positions`: record_list — Closed-trade records (Unix-seconds times).
235
+
236
+ Params:
237
+ - `trader_address`: str (default: required) — The trader wallet whose closed-trade history to read (required).
238
+ - `limit`: int (default: 100) [1..1000] — Maximum closed positions to return (most recent first).
239
+
240
+ Cost: One discovery_get_trader_history MCP call per tick.
241
+
242
+ Example:
243
+ ```yaml
244
+ node: trader_history_fetch
245
+ with:
246
+ trader_address: "0xTRADER"
247
+ limit: 100
248
+ ```
249
+
250
+ ## trader_state_fetch (source)
251
+
252
+ discovery_get_trader_state for a given wallet, reduced to (held, equity) — the same contract as clearinghouse_state but generalized OFF the strategy's own wallet to ANY trader (a leaderboard entry / smart-money address). Enables copy-trading and leaderboard-following archetypes. Same read-sanity guard as clearinghouse_state (notional-in-use but empty positions -> corrupt read).
253
+
254
+ Inputs:
255
+ - (none)
256
+
257
+ Outputs:
258
+ - `held`: asset_list — Assets the trader currently holds.
259
+ - `equity`: scalar — The trader's account value.
260
+
261
+ Params:
262
+ - `trader_address`: str (default: required) — The trader wallet whose current book to read (required).
263
+
264
+ Cost: One discovery_get_trader_state MCP call per tick.
265
+
266
+ Example:
267
+ ```yaml
268
+ node: trader_state_fetch
269
+ with:
270
+ trader_address: "0xTRADER"
271
+ ```
272
+
273
+ ## universe_discover (source)
274
+
275
+ Applies a field predicate over instrument_list output to derive the tradeable set (magpie's IPOP funding-signature). Generalizes thesis-fund's 'is this on the live board' check as the identity predicate. Pure compute over the instrument list.
276
+
277
+ Inputs:
278
+ - `instruments`: asset_list — Candidate instruments from instrument_list.
279
+
280
+ Outputs:
281
+ - `universe`: asset_list — Instruments passing the membership predicate.
282
+
283
+ Params:
284
+ - `min_day_volume`: float (default: 0.0) [0.0..] — Minimum dayNtlVlm floor (magpie liquidity gate).
285
+ - `max_leverage_cap`: float (default: 5.0) [1.0..] — Reject instruments whose max leverage exceeds this (magpie <=5).
286
+ - `name_prefix`: str (default: '') — Require instrument name to start with this prefix (magpie 'xyz:').
287
+
288
+ Cost: Pure compute over instrument_list output; no extra MCP call.
289
+
290
+ Example:
291
+ ```yaml
292
+ node: universe_discover
293
+ with:
294
+ name_prefix: "xyz:"
295
+ max_leverage_cap: 5
296
+ ```
297
+
298
+ ## acceleration (indicator)
299
+
300
+ stag's acceleration test: short-window move >= half the long-window move (a boolean gate).
301
+
302
+ Inputs:
303
+ - `candles`: candles — Source candles.
304
+
305
+ Outputs:
306
+ - `accelerating`: feature_map — Per-asset boolean acceleration flag.
307
+
308
+ Params:
309
+ - `short_window`: int (default: 3) [1..] — Short move window.
310
+ - `long_window`: int (default: 6) [2..] — Long move window.
311
+ - `interval`: str (default: '4h') — Candle interval to read.
312
+
313
+ Cost: Pure compute over candles.
314
+
315
+ Example:
316
+ ```yaml
317
+ node: acceleration
318
+ with:
319
+ short_window: 3
320
+ long_window: 6
321
+ ```
322
+
323
+ ## breakout_detect (indicator)
324
+
325
+ hawk's breakout: LONG if the latest close breaks the prior-`window` high, SHORT if it breaks the low, else NEUTRAL.
326
+
327
+ Inputs:
328
+ - `candles`: candles — Source candles.
329
+
330
+ Outputs:
331
+ - `direction`: feature_map — Per-asset LONG / SHORT / NEUTRAL breakout.
332
+
333
+ Params:
334
+ - `window`: int (default: 168) [2..] — Prior-close window (hawk 168h).
335
+ - `interval`: str (default: '1h') — Candle interval to read.
336
+
337
+ Cost: Pure compute over candles.
338
+
339
+ Example:
340
+ ```yaml
341
+ node: breakout_detect
342
+ with:
343
+ window: 168
344
+ interval: "1h"
345
+ ```
346
+
347
+ ## pct_change (indicator)
348
+
349
+ Percent change of close over `lookback` bars (stag 7d trend %; bison/thesis-fund price momentum — same shape, different window).
350
+
351
+ Inputs:
352
+ - `candles`: candles — Source candles.
353
+
354
+ Outputs:
355
+ - `pct`: feature_map — Per-asset percent change over the window.
356
+
357
+ Params:
358
+ - `lookback`: int (default: 42) [1..] — Bars to look back (stag 7d ~= 42 x 4h).
359
+ - `interval`: str (default: '4h') — Candle interval to read.
360
+
361
+ Cost: Pure compute over candles.
362
+
363
+ Example:
364
+ ```yaml
365
+ node: pct_change
366
+ with:
367
+ lookback: 42
368
+ interval: "4h"
369
+ ```
370
+
371
+ ## recent_high_bars_ago (indicator)
372
+
373
+ Counts bars since the highest high within `window` (stag's fresh-high freshness check).
374
+
375
+ Inputs:
376
+ - `candles`: candles — Source candles.
377
+
378
+ Outputs:
379
+ - `bars_ago`: feature_map — Per-asset bars since the window high.
380
+
381
+ Params:
382
+ - `window`: int (default: 60) [2..] — Bars in the high-water window.
383
+ - `interval`: str (default: '4h') — Candle interval to read.
384
+
385
+ Cost: Pure compute over candles.
386
+
387
+ Example:
388
+ ```yaml
389
+ node: recent_high_bars_ago
390
+ with:
391
+ window: 60
392
+ ```
393
+
394
+ ## rsi (indicator)
395
+
396
+ Trailing-window RSI over the last `period` gains/losses (duplicated verbatim in bison and thesis-fund).
397
+
398
+ Inputs:
399
+ - `candles`: candles — Source candles.
400
+
401
+ Outputs:
402
+ - `rsi`: feature_map — Per-asset RSI in [0,100].
403
+
404
+ Params:
405
+ - `period`: int (default: 14) [2..100] — RSI lookback (default 14).
406
+ - `interval`: str (default: '1h') — Candle interval to read.
407
+
408
+ Cost: Pure compute over candles.
409
+
410
+ Example:
411
+ ```yaml
412
+ node: rsi
413
+ with:
414
+ period: 14
415
+ interval: "1h"
416
+ ```
417
+
418
+ ## sma (indicator)
419
+
420
+ Simple moving average over `period` closes at `interval`, plus a close>SMA flag (stag SMA-200 trend gate).
421
+
422
+ Inputs:
423
+ - `candles`: candles — Source candles.
424
+
425
+ Outputs:
426
+ - `value`: feature_map — Per-asset SMA of close.
427
+ - `above`: feature_map — Per-asset boolean: close above the SMA.
428
+
429
+ Params:
430
+ - `period`: int (default: 200) [1..1000] — Lookback in bars (stag uses 200).
431
+ - `interval`: str (default: '4h') — Candle interval to read.
432
+
433
+ Cost: Pure compute over candles.
434
+
435
+ Example:
436
+ ```yaml
437
+ node: sma
438
+ with:
439
+ period: 200
440
+ interval: "4h"
441
+ ```
442
+
443
+ ## trend_structure (indicator)
444
+
445
+ Classifies LONG (higher lows) / SHORT (lower highs) / NEUTRAL over `lookback` bars. This is the single highest-value dedup target: literally duplicated across hawk, bison (x2), magpie, and thesis-fund — 6 corpus call-sites, one primitive.
446
+
447
+ Inputs:
448
+ - `candles`: candles — Source candles.
449
+
450
+ Outputs:
451
+ - `direction`: feature_map — Per-asset LONG / SHORT / NEUTRAL.
452
+
453
+ Params:
454
+ - `lookback`: int (default: 6) [2..] — Swing lookback in bars.
455
+ - `interval`: str (default: '4h') — Candle interval (called at 4h and 1h).
456
+
457
+ Cost: Pure compute over candles.
458
+
459
+ Example:
460
+ ```yaml
461
+ node: trend_structure
462
+ with:
463
+ lookback: 6
464
+ interval: "4h"
465
+ ```
466
+
467
+ ## volume_surge_ratio (indicator)
468
+
469
+ Unifies stag's volume_surge, hawk's volume_ratio, and bison's volume_trend into one parameterized primitive: mean(recent_window) / mean(baseline_window) volume.
470
+
471
+ Inputs:
472
+ - `candles`: candles — Source candles.
473
+
474
+ Outputs:
475
+ - `ratio`: feature_map — Per-asset recent/baseline volume ratio.
476
+
477
+ Params:
478
+ - `recent_window`: int (default: 6) [1..] — Recent window (stag 6).
479
+ - `baseline_window`: int (default: 42) [1..] — Baseline window (stag 42).
480
+ - `interval`: str (default: '4h') — Candle interval to read.
481
+
482
+ Cost: Pure compute over candles.
483
+
484
+ Example:
485
+ ```yaml
486
+ node: volume_surge_ratio
487
+ with:
488
+ recent_window: 6
489
+ baseline_window: 42
490
+ ```
491
+
492
+ ## classifier_predicate (filter)
493
+
494
+ magpie's funding-signature IPOP test generalized: a named boolean predicate over instrument fields (funding magnitude, max leverage, delisting). Distinct from universe_discover in that it classifies an existing candidate set rather than deriving one.
495
+
496
+ Inputs:
497
+ - `candidates`: asset_list — Candidate instruments with venue fields. [optional]
498
+
499
+ Outputs:
500
+ - `kept`: asset_list — Candidates passing every field predicate.
501
+
502
+ Params:
503
+ - `max_funding_abs`: float (default: 1e-07) [0.0..] — Reject if |funding| exceeds this (magpie 1e-7).
504
+ - `max_leverage`: float (default: 5.0) [1.0..] — Reject if venue max leverage exceeds this (magpie <=5).
505
+ - `exclude_delisted`: bool (default: True) — Drop delisted instruments.
506
+
507
+ Cost: Pure compute; no MCP call.
508
+
509
+ Example:
510
+ ```yaml
511
+ node: classifier_predicate
512
+ with:
513
+ max_funding_abs: 0.0000001
514
+ max_leverage: 5
515
+ ```
516
+
517
+ ## held_asset_exclusion (filter)
518
+
519
+ Removes any candidate present in the held-position set (all five packages do this).
520
+
521
+ Inputs:
522
+ - `candidates`: asset_list — Candidate assets. [optional]
523
+ - `held`: asset_list — Currently-held assets from clearinghouse_state.
524
+
525
+ Outputs:
526
+ - `kept`: asset_list — Candidates not currently held.
527
+
528
+ Params:
529
+ - (none)
530
+
531
+ Cost: Pure compute; no MCP call.
532
+
533
+ Example:
534
+ ```yaml
535
+ node: held_asset_exclusion
536
+ ```
537
+
538
+ ## live_instrument_validation (filter)
539
+
540
+ Intersects candidates with the live instrument board (thesis-fund explicit; magpie implicit via universe_discover).
541
+
542
+ Inputs:
543
+ - `candidates`: asset_list — Candidate assets. [optional]
544
+ - `instruments`: asset_list — Live board from instrument_list.
545
+
546
+ Outputs:
547
+ - `kept`: asset_list — Candidates still tradeable.
548
+
549
+ Params:
550
+ - (none)
551
+
552
+ Cost: Pure compute; no MCP call.
553
+
554
+ Example:
555
+ ```yaml
556
+ node: live_instrument_validation
557
+ ```
558
+
559
+ ## recent_signal_ttl_dedup (filter)
560
+
561
+ Removes candidates that appear in the recently-signaled set produced by ttl_dedup_state (all five packages dedup this way). The TTL itself is owned by the stateful node; this filter only applies the resulting exclusion set.
562
+
563
+ Inputs:
564
+ - `candidates`: asset_list — Candidate assets. [optional]
565
+ - `recent`: asset_list — Assets signaled within TTL (from ttl_dedup_state).
566
+
567
+ Outputs:
568
+ - `kept`: asset_list — Candidates not recently signaled.
569
+
570
+ Params:
571
+ - (none)
572
+
573
+ Cost: Pure compute; no MCP call.
574
+
575
+ Example:
576
+ ```yaml
577
+ node: recent_signal_ttl_dedup
578
+ ```
579
+
580
+ ## hard_gates_all (scorer)
581
+
582
+ stag's 5/5 hard gates and hawk's 2 required gates + 3 score-only contributors. `required_gates` names feature keys that must all be truthy; `weights` scores the remaining contributors into a weighted sum with reasons[].
583
+
584
+ Inputs:
585
+ - `features`: feature_map — Merged per-asset feature record. [merge]
586
+
587
+ Outputs:
588
+ - `scores`: score_map — Per-asset {score, reasons[]} for gate-passers.
589
+
590
+ Params:
591
+ - `required_gates`: list[str] (default: []) — Feature keys that must ALL be truthy (stag's 5 gates).
592
+ - `weights`: map_str_float (default: {}) — Feature-key -> weight for the weighted-sum score (bespoke edge slot).
593
+ - `min_score`: float (default: 0.0) [0.0..] — Minimum score to keep the candidate.
594
+
595
+ Cost: Pure compute over the feature map.
596
+
597
+ Example:
598
+ ```yaml
599
+ node: hard_gates_all
600
+ with:
601
+ required_gates: ["above", "accelerating"]
602
+ min_score: 3
603
+ ```
604
+
605
+ ## emit_single_best (ranker)
606
+
607
+ stag/hawk/bison (and magpie implicitly, since its universe is tiny): sort descending, keep the top 1 above `min_score`.
608
+
609
+ Inputs:
610
+ - `scores`: score_map — Scored candidates.
611
+
612
+ Outputs:
613
+ - `selected`: score_map — The single highest-scoring candidate.
614
+
615
+ Params:
616
+ - `min_score`: float (default: 0.0) — Floor below which nothing is emitted.
617
+
618
+ Cost: Pure compute over the score map.
619
+
620
+ Example:
621
+ ```yaml
622
+ node: emit_single_best
623
+ with:
624
+ min_score: 3
625
+ ```
626
+
627
+ ## rank_pool_cap_to_open_slots (ranker)
628
+
629
+ thesis-fund's rank-pool-then-cap: sort all confirming candidates descending, emit the top N where N = max_slots minus the count currently held.
630
+
631
+ Inputs:
632
+ - `scores`: score_map — Scored candidates.
633
+ - `held`: asset_list — Held assets, to compute open slots.
634
+
635
+ Outputs:
636
+ - `selected`: score_map — Top (max_slots - held) candidates.
637
+
638
+ Params:
639
+ - `max_slots`: int (default: 5) [1..50] — Maximum concurrent positions.
640
+ - `min_score`: float (default: 0.0) — Floor below which a candidate is dropped.
641
+
642
+ Cost: Pure compute over the score map.
643
+
644
+ Example:
645
+ ```yaml
646
+ node: rank_pool_cap_to_open_slots
647
+ with:
648
+ max_slots: 5
649
+ ```
650
+
651
+ ## signal_envelope (emitter)
652
+
653
+ Maps selected candidates to the scan contract's return shape: {asset, direction, marginPct(0,100], leverage, data{score, reasons[], ...}} plus the optional scaffold-recognized keys valid_for_seconds (TTL override) and signal_type. Every scanner-settable signal field is expressible — statically via params, or dynamically per-asset via the score_map `selected` entry (marginPct, leverage, valid_for_seconds, signal_type, data). When `clamp_leverage_to_venue` is true AND the live board is wired into `instruments`, each signal's leverage is clamped to that instrument's venue max exactly as the corpus clamp_leverage does (byte-identical across magpie/thesis-fund); no `instruments` wire = no-op passthrough.
654
+
655
+ Inputs:
656
+ - `selected`: score_map — Ranked/selected candidates to emit.
657
+ - `equity`: scalar — Account equity for sizing (optional wiring). [optional]
658
+ - `instruments`: asset_list — Live venue board (instrument_list records) for the real per-asset leverage clamp; unwired leaves clamp_leverage_to_venue a no-op. [optional]
659
+
660
+ Outputs:
661
+ - `signals`: signals — The scan() return: list of signal dicts.
662
+
663
+ Params:
664
+ - `margin_pct`: float (default: 5.0) [0.0001..100.0] — Percent of withdrawable to allocate, (0,100] (never a fraction or USD).
665
+ - `leverage`: float (default: 3.0) [1.0..50.0] — Requested leverage before any venue clamp.
666
+ - `clamp_leverage_to_venue`: bool (default: True) — Clamp leverage down to the instrument's venue max (magpie/thesis-fund).
667
+ - `valid_for_seconds`: int (default: 0) [0..] — Per-signal TTL override in seconds; 0 = inherit the runtime default TTL.
668
+ - `signal_type`: str (default: '') — Optional signal_type label carried on every emitted signal ('' = none).
669
+
670
+ Cost: Pure compute; produces the scan() return value.
671
+
672
+ Example:
673
+ ```yaml
674
+ node: signal_envelope
675
+ with:
676
+ margin_pct: 5
677
+ leverage: 3
678
+ ```
679
+
680
+ ## ttl_dedup_state (stateful)
681
+
682
+ The universal signal-dedup pattern (all five packages): appends each tick's emitted signals to ctx.state, prunes entries older than prune_factor x TTL, and exposes the assets still within TTL as the `recent` exclusion set consumed by recent_signal_ttl_dedup. Declares the state in/out port pair (D2).
683
+
684
+ Inputs:
685
+ - `emitted`: signals — Signals emitted this tick, to record.
686
+ - `state_in`: state — Incoming ctx.state (D2 state port). [optional]
687
+
688
+ Outputs:
689
+ - `recent`: asset_list — Assets signaled within TTL (exclusion set).
690
+ - `state_out`: state — Updated ctx.state after append + prune (D2 state port).
691
+
692
+ Params:
693
+ - `ttl_seconds`: int (default: 240) [1..] — Dedup window in seconds (stag/hawk 240, bison/thesis-fund 180, magpie 720).
694
+ - `prune_factor`: int (default: 4) [1..] — Prune entries older than prune_factor x TTL (hawk prunes at 4x).
695
+
696
+ Cost: Reads/writes ctx.state; no MCP call.
697
+
698
+ Example:
699
+ ```yaml
700
+ node: ttl_dedup_state
701
+ with:
702
+ ttl_seconds: 240
703
+ ```