Skip to content

Commit 052deae

Browse files
luisleo526claude
andcommitted
report: opt-in replay extension (raw realized P&L, settlement markers, equity members, companion stream)
Adds, strictly opt-in (--report-replay, --report-replay-sink), what a validator needs to replay a run exactly: - the raw whole-lot realized P&L (net_profit_sum_), with the initial capital and the point value, through one additive nonvirtual accessor (strategy_net_profit_sum; ABI version unchanged); - per closed trade the original physical-close settlement index and a recut marker (parent id as a decimal string, slice index and count, recomputed fields, child index, transaction and whole-lot operands, fee operands), retained through the global-exit recut, the same-bar sort and sealing; - per equity point the settlement count, the raw sum, the equity basis and the term before capital; - a separate companion stream (pf-report-replay/v1) with its own count, hash and trailer, bound to the primary sink digest; the primary sink bytes and the default JSON are unchanged when the extension is off; - run_json and pf_sink pass-through, and the companion reader/validator that checks the exact replay in bits (left fold from +0.0 of the whole-lot P&L per settlement index, no tolerance); - tests (real-engine runs, vectors, companion grammar and negatives, a baseline byte-identity row), the documentation, and the registrations the repository guards require for the new surface. Documentation line anchors were re-pointed to the moved lines. The sentence changes the revert guard reports in docs/design/native-feature-parity.md (introduced by 1dd5430 and 91353de) and docs/native-refactor-progress.md (introduced by d093560) are line-number updates of existing anchors, plus the removal of a level label from one table cell; no documented fact is changed. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent 95f4fd1 commit 052deae

61 files changed

Lines changed: 5440 additions & 388 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ set(PINEFORGE_KERNEL_SOURCES src/array.cpp
126126
src/engine_execution.cpp
127127
src/engine_path_resolve.cpp
128128
src/engine_report.cpp
129+
src/report_replay.cpp
129130
src/reservation_expansion.cpp
130131
src/engine_run.cpp
131132
src/engine_security.cpp

‎README.md‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ The separate PineForge compiler, [`pineforge-codegen`](https://github.com/pinefo
3333
- **Open runtime.** The engine and native live runner are Apache-2.0. The separately distributed [PineForge compiler](https://github.com/pineforge-4pass/pineforge-codegen-oss/blob/main/LICENSE) is source-available under the PineForge Source License 1.2 from its release 1.3.0 (release 1.2.0 keeps the PineForge Source License 1.1, and releases up to 1.1.0 keep the PolyForm Noncommercial terms they shipped with); personal trading is free, and commercial use requires a separate license; the capital in an account a proprietary-trading firm or funded-trader program provides or allocates, including a challenge, evaluation or simulated account, is investment capital. Public reference strategies, benchmarks and validation tooling are available in their respective repositories; the community-script test set is not redistributed.
3434
- **Fast.** In-process, no interpreter: median **36× faster than PyneCore** on the 200 strategies both engines time (100 corpus probes and 100 held-out private strategies), measured at engine `35db01c8` on 2026-09-29 on an AWS c7a.8xlarge with PyneCore timed as a subprocess, its interpreter start-up included (PineForge runs a median 807k bars/s per strategy over its 201 slots with the bar magnifier on; [method](benchmarks/results/speed.md)). Parameter sweeps re-run a loaded `.so` with new inputs — no recompile, no fork.
3535
- **Deterministic to the bit.** Two runs with the same inputs produce identical trade lists.
36-
- **Yours to embed.** 159 `PF_API` declarations across six installed headers — `pineforge.h`'s 103 (83 of the 94 runtime exports and up to 20 per-strategy functions a generated module defines), eleven more runtime declarations in `execution_observer.h`, `selected_window.h` and `report_sink.h` (three, three and five), `native_c_api.h`'s 43 native-host declarations and `selected_window_plan.h`'s two planner declarations — an ABI that is append-only within a major version from 1.0 on. Call it from C, Python, Rust, Go, Node, Julia — or let an AI agent drive it over MCP.
36+
- **Yours to embed.** 162 `PF_API` declarations across six installed headers — `pineforge.h`'s 106 (86 of the 97 runtime exports and up to 20 per-strategy functions a generated module defines), eleven more runtime declarations in `execution_observer.h`, `selected_window.h` and `report_sink.h` (three, three and five), `native_c_api.h`'s 43 native-host declarations and `selected_window_plan.h`'s two planner declarations — an ABI that is append-only within a major version from 1.0 on. Call it from C, Python, Rust, Go, Node, Julia — or let an AI agent drive it over MCP.
3737

3838
Recorded outputs and their additional API declarations described here are
3939
part of **1.5.0**.
@@ -540,11 +540,11 @@ is in [CHANGELOG.md](CHANGELOG.md).
540540

541541
The counts below describe the current API, including recorded outputs, the report sink and scratch-table selection; recorded outputs are not part of 1.4.0.
542542

543-
A newly generated strategy `.so` exposes 110 compiled-strategy `PF_API` declarations
544-
(94 runtime implementations plus sixteen generated exports) plus 43 native-host
545-
declarations: 153 `PF_API` exports in total; `use_bar_magnifier = true` adds
543+
A newly generated strategy `.so` exposes 113 compiled-strategy `PF_API` declarations
544+
(97 runtime implementations plus sixteen generated exports) plus 43 native-host
545+
declarations: 156 `PF_API` exports in total; `use_bar_magnifier = true` adds
546546
`strategy_declares_bar_magnifier` and a module that records [outputs](docs/outputs.md) its
547-
three outputs exports, bringing the inventories to at most 114 and 157. Older modules lack the six opt-in
547+
three outputs exports, bringing the inventories to at most 117 and 160. Older modules lack the six opt-in
548548
[checked-settings exports](docs/checked-settings.md). Older modules can also lack
549549
the two opt-in [execution-capability exports](docs/strategy-capabilities.md).
550550
In an optimized build `nm -gU` also shows libc++'s
@@ -590,6 +590,8 @@ inventories are pinned by `scripts/check_c_abi_runtime.py`:
590590
| `strategy_position_avg_price` / `strategy_position_cycle_seq` / `strategy_position_size` | ABI v4: the live position's volume-weighted average entry price, its cycle id, and its script-facing signed size |
591591
| `strategy_closed_trade_entry_id` / `_exit_id` / `_exit_comment` / `_close_cause` | ABI v4: per-closed-trade id/comment strings and a `close_cause` (`pf_close_cause_t`: `SCRIPT`, `BRACKET`, `LIQUIDATION` for a margin call, `RISK_LIMIT` for the intraday loss cap, `FILL_CAP` for the intraday fill cap, `RANGE_END`), indexed like `strategy_closed_trade_entry_incarnation` |
592592
| `strategy_initial_capital` | ABI v4: the engine's effective configured initial capital, after the native run specification or strategy override; `NaN` if `s` is `NULL` or the read raises |
593+
| `strategy_net_profit_sum` / `strategy_report_pointvalue` | ABI v4 additive replay accessors: raw whole-lot realized P&L and effective pointvalue; `NaN` on `NULL` |
594+
| `strategy_set_report_replay_v1` | Opt in to a separate [report replay companion](docs/pages/report-replay-rq.md) while idle; no existing report or sink layout changes |
593595
| `strategy_current_equity` / `strategy_script_bars_processed` | ABI v4: `initial_capital + netprofit` (not Pine's `strategy.equity`, which also adds open profit); total script bars dispatched by the most recent run |
594596

595597
### Driving the kernel from C

0 commit comments

Comments
 (0)