Skip to content

Commit e7cdf05

Browse files
luisleo526claudecodex
authored
Add native execution terms: host-resolved sizing, exact reversal, precommit view, FX curve (R4-B) (#251)
* Freeze the epoch-14 native provider header closure from f736676 Track the exact 55-file include closure of the last engine_script_run_v14 commit (PR #250 squash f736676, tree c69421f) as a fixture, authenticated per file by size, SHA-256 and Git blob, before any epoch-15 edit begins. The preparation tool will build the real immutable source with each profile's compiler and configuration; nothing here is wired yet. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_013y1CvsXqLFMRgAW7TXJQMs * Rename native epochs to v15/v4 and wire the frozen v14 provider Rename engine/host and order namespaces, the host capability macro, and consumer/broker/stream identity markers without changing engine behavior or existing C++ numeric assertions. Preserve the six measured files and normalize only the identity header's stale namespace comment. Generalize the ABI fence to the reviewed v13/v14-to-v15 pairs, pin the Phase-0 header bytes, and derive authenticated provider owners and each caller's order shape. Prepare and verify the frozen f736676 v14 archive alongside e60, 0e, v13 and current v15, including unchanged-driver links. Stage complete execution-terms/FX callers and the named negative compile control behind the Phase-1c readiness gate. Activate the authenticated v14 compile control, retain all old order-v1 pairs, and update registered Python mirrors, CMake receipts, CI diagnostics and epoch documentation. Validation: ci_preflight passed; full Release ci_verify passed all 334 registered tests with zero failures/skips; the unregistered native-feed mirror passed 5 tests. The five-archive matrix passed 49 compiles and 118 links. R-EPOCH matches the 16 recorded historical/control residuals. Co-Authored-By: Codex gpt-6-astra <[email protected]> * Add the native FX-curve value header and its validation Add NativeFxCurve v1 values, ordered validation, and the total length-prefixed FNV digest. Register the source and validation/digest test, plus exact ownership, include-freedom, and introduced-at controls. Contract: §3.4, §6, §7 1a, Appendix C rows 32 and 40, amendment A5. Co-Authored-By: Codex gpt-6-astra <[email protected]> * Add native_order_v4 execution terms core with deferred sizing and exact reversal Add the v4 order terms surface, deferred allowance and authenticated binding receipts, exact reversal and whole-close accounting, durable receipt hashing, ABI shape pins, and core witnesses. Contract: §3.1, §4.1–§4.2, §6, §7 (landing 1b), §8 (A-T1, A-T3, A-T4, A-T4d, A-R5, A-R6, A-S2, A-S3, A-S4, A-H1, A-1). Co-Authored-By: Codex gpt-6-astra <[email protected]> * Declare the v15 native host terms, precommit and FX-curve surface Add the complete v15 host values, identity resolver and precommit defaults, plus Ready-only FX-curve staging with a durable continuation-hash fold. Register the five phase-1 seed witnesses, re-pin the host ABI bytes, and activate the V15 ABI controls and mirrors. Contract: §3.2, §3.5, §4.4, §6, §7 (Landing 1c), A-1, A-A2. Co-Authored-By: Codex gpt-5.6-terra <[email protected]> * Pin the A-R6 reversal accounting witnesses fully Fully assert reversal allowance and remaining projections, including the absorbed-turnover witness. Contract rules: §3.1, §4.2, §8 A-R6, §9 A-0. Co-Authored-By: Codex gpt-5.6-terra <[email protected]> * Implement native execution terms coordinator Add the W2 resolver, matcher provenance, plan dispatch, precommit, and FX activation seams under R4-B §§3.2, 3.3, 3.5, 4.1–4.4, 5, and amendment A1/A2.\n\nA6: append and hash the durable shared_cursor_collision receipt field. Co-Authored-By: Codex gpt-5.6-terra <[email protected]> * Add native terms coordinator witnesses Exercise host-sized terms, provenance collisions, reversal/whole-close plans, precommit barriers, FX activation, and durable replay/serializer branches under R4-B §7–§8 and amendments A1–A4. Co-Authored-By: Codex gpt-5.6-terra <[email protected]> * Cover native terms provenance and serialization Add test-only oracle, current terms facts, deferred cancellation, collision replay, projection barriers, and executable replay/market/calendar serializer controls for R4-B §7–§10 and amendments A1–A4. Co-Authored-By: Codex gpt-5.6-terra <[email protected]> * Validate native host terms before receipt Reject invalid opening-shape values and limit-breaching host prices before receipt installation under R4-B §4.1. Co-Authored-By: Codex gpt-5.6-terra <[email protected]> * Expand native terms acceptance matrix Add literal W2 coordinator witnesses for R4-B §8 terms, reversal, precommit, FX, provenance, and post-hook rows. Co-Authored-By: Codex gpt-5.6-terra <[email protected]> * Add literal W2 terms acceptance rows Cover expanded R4-B §8 terms, price provenance, reversal, precommit, FX, and hash/replay witnesses in the assigned W2 test files. Co-Authored-By: Codex gpt-5.6-terra <[email protected]> * Broaden W2 acceptance witnesses Add queued cancellation, price-kind, price-boundary, exact reversal, barrier, and fresh-replay acceptance rows required by R4-B §8. Co-Authored-By: Codex gpt-5.6-terra <[email protected]> * Complete W2 replay and serializer controls Add assigned W2 provenance, precommit barrier, replay hash, and calendar binary64 serializer acceptance coverage under R4-B §7–§8. Co-Authored-By: Codex gpt-5.6-terra <[email protected]> * Strengthen current facts and FX sink coverage Add all current fact-shape comparisons and native candidate timestamp sink witnesses for assigned R4-B W2 rows. Co-Authored-By: Codex gpt-5.6-terra <[email protected]> * Exercise precommit cycle exhaustion boundary Add the W2 A-P4 pre-effects cycle-exhaustion witness with zero validator calls. Co-Authored-By: Codex gpt-5.6-terra <[email protected]> * Fix native terms review defects Address zero-unit nonpositive terms, callback activation timestamp, provenance invalidation, and complete TermsResolved serializer coverage per W2 review D1-D3. Co-Authored-By: Codex gpt-5.6-terra <[email protected]> * Complete durable terms serialization and replay tests Serialize complete TermsResolved identities/projections and add real market/calendar lifecycle plus appended-history replay witnesses for D3/D4. Co-Authored-By: Codex gpt-5.6-terra <[email protected]> * Preserve zero-unit terms across price fences Ensure valid HostSized zero terminals install their receipt and NoEffect even at nonpositive or limit-side prices. Co-Authored-By: Codex gpt-5.6-terra <[email protected]> * docs: correct carried FX rollover support Correct the public C ABI documentation to state that carried 1× long and short positions are supported while leveraged positions fail closed. Contract: §3.4, §6, §11, Appendix C row 35. Co-Authored-By: Codex gpt-6-astra <[email protected]> * Add native FX curve C ABI transport Add the Ready-only FX curve C entry, runtime export inventory, and direct and dynamic C caller coverage. Extend the v15 ownership and exact-count ABI fences with registered mirrors. Contract: §3.4, §6, §7; A-F1, A-A1, A-A2, A-E2. Co-Authored-By: Codex gpt-5.6-terra <[email protected]> * docs: describe native execution terms v15 Document the R4-B native terms, exact reversal, precommit, FX-curve, ABI transition, and runner examples. Contract: §3.2, §3.4, §3.6, §6, §7 W4, §11; A-E1, A-E2. Co-Authored-By: Codex gpt-6-astra <[email protected]> * test: add native selected strategy example Add the v15 selected native runner module, its dynamic batch/stream test, and the final ABI/example documentation refinements. Contract: §7 W4, §8 fail-before protocol, A-E1, A-E2, and R-EPOCH. Co-Authored-By: Codex gpt-5.6-terra <[email protected]> * docs: correct the native refactor progress record Record PR #247 and PR #248 as completed R3 milestones, and separate PR #246 historical epoch-13 state from the current R4-B baseline. Contract: §6 R-EPOCH rule 3; Appendix A; A-E2. Co-Authored-By: Codex gpt-5.6-terra <[email protected]> * docs: add native refactor worker guidance Apply the root-authored worker guidance patches for the R4-B integration. Contract: R4-B §§0, 7, 8, 9. Co-Authored-By: Codex gpt-5.6-terra <[email protected]> * fix: re-pin reviewed native ABI headers Re-pin the recorded A6 native_order and integrated native_host bytes after phase-3 review. Contract: R4-B §§6–7; amendment A6. Co-Authored-By: Codex gpt-5.6-terra <[email protected]> * Drop identity attempted terms and complete the terms acceptance rows Repair the explicit identity ReverseTo rejection metadata and add literal A-T5, A-T6, A-T9, A-S2, A-P1, and A-F7 witnesses. Contract: §3.1, §4.1-§4.4, §8; A-T5, A-T6, A-T9, A-S2, A-P1, A-F7. Co-Authored-By: Codex gpt-5.6-terra <[email protected]> --------- Co-authored-by: Claude Fable 5.1 <[email protected]> Co-authored-by: Codex gpt-6-astra <[email protected]>
1 parent f736676 commit e7cdf05

75 files changed

Lines changed: 9279 additions & 541 deletions

File tree

Some content is hidden

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

‎AGENTS.md‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,42 @@ they are codegen-emitted; the checker enforces exactly that split.
8585
- Keep helper functions inline or in clean namespaces.
8686
- Do not add external dependencies without explicit user request.
8787

88+
## Refactor workers (native-engine programme, R4 and later)
89+
90+
Applies to any agent — Claude, Codex, OpenCode — implementing a slice of the
91+
native-engine refactor in this repository. The campaign repo's standing
92+
orders (`pineforge-workflow/AGENTS.md`, "Roles and dispatch") govern who
93+
dispatches, reviews and measures; this section is what binds you here.
94+
95+
- You work in the worktree and branch your brief names, on the files it
96+
lists as yours, and nowhere else. A need in another file is reported to the
97+
supervisor, never edited quietly. You never push; the supervisor opens the
98+
PR after the one campaign sweep.
99+
- A neutral refactor never opens the measured sources
100+
(`src/engine_strategy_commands.cpp`, `engine_fills.cpp`, `engine_orders.cpp`,
101+
`engine_risk.cpp`, `engine_run.cpp`, `engine_market_admission.cpp`) and
102+
never edits the frozen native headers the settlement ABI checker names; the
103+
fixed parity population must stay byte-identical by construction, which the
104+
supervisor proves with the sweep, not you.
105+
- C++17 only (`rg 'bit_cast|<bit>' src include tests scripts` = 0). Every
106+
added durable state is hashed. Existing numeric assertions and fixture
107+
outputs stay unchanged unless the contract lists the extension.
108+
- Every new test unit is compiled first against the frozen previous-epoch
109+
header closure and its first diagnostic is recorded (fail-before). A test
110+
whose body is a seed row only, a `return 0` main, a disabled row or a TODO
111+
placeholder is a blocker to report, never evidence.
112+
- Verification is local: `python3 scripts/ci_preflight.py`, then
113+
`python3 scripts/ci_verify.py release --build-dir <your dir> --jobs N` (all
114+
suites, the settlement ABI matrix, the checker self-tests); debug,
115+
sanitizers and native profiles when the brief asks. No campaign sweep from
116+
a worker.
117+
- Your handoff is a report: HEAD sha, `git diff --stat <base>..HEAD`, the
118+
verification summary lines and log paths, every deviation from the
119+
contract with its reason, and every open question. The supervisor judges
120+
the slice by its executed result: no regression in the campaign sweep, the
121+
engine closer to an independent backtest + forward-execution state
122+
machine, and Pine-parity behaviour kept in codegen with this kernel clean.
123+
88124
## Parity campaign gate (applies on EVERY harness)
89125

90126
Pushes and PRs from this repo are gated by the PineForge parity campaign: a

‎CLAUDE.md‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,39 @@ they are codegen-emitted; the checker enforces exactly that split.
8484
- Follow existing patterns for trade accessors and order management.
8585
- Keep helper functions inline or in clean namespaces.
8686
- Do not add external dependencies without explicit user request.
87+
88+
## Refactor workers (native-engine programme, R4 and later)
89+
90+
Applies to any agent — Claude, Codex, OpenCode — implementing a slice of the
91+
native-engine refactor in this repository. The campaign repo's standing
92+
orders (`pineforge-workflow/AGENTS.md`, "Roles and dispatch") govern who
93+
dispatches, reviews and measures; this section is what binds you here.
94+
95+
- You work in the worktree and branch your brief names, on the files it
96+
lists as yours, and nowhere else. A need in another file is reported to the
97+
supervisor, never edited quietly. You never push; the supervisor opens the
98+
PR after the one campaign sweep.
99+
- A neutral refactor never opens the measured sources
100+
(`src/engine_strategy_commands.cpp`, `engine_fills.cpp`, `engine_orders.cpp`,
101+
`engine_risk.cpp`, `engine_run.cpp`, `engine_market_admission.cpp`) and
102+
never edits the frozen native headers the settlement ABI checker names; the
103+
fixed parity population must stay byte-identical by construction, which the
104+
supervisor proves with the sweep, not you.
105+
- C++17 only (`rg 'bit_cast|<bit>' src include tests scripts` = 0). Every
106+
added durable state is hashed. Existing numeric assertions and fixture
107+
outputs stay unchanged unless the contract lists the extension.
108+
- Every new test unit is compiled first against the frozen previous-epoch
109+
header closure and its first diagnostic is recorded (fail-before). A test
110+
whose body is a seed row only, a `return 0` main, a disabled row or a TODO
111+
placeholder is a blocker to report, never evidence.
112+
- Verification is local: `python3 scripts/ci_preflight.py`, then
113+
`python3 scripts/ci_verify.py release --build-dir <your dir> --jobs N` (all
114+
suites, the settlement ABI matrix, the checker self-tests); debug,
115+
sanitizers and native profiles when the brief asks. No campaign sweep from
116+
a worker.
117+
- Your handoff is a report: HEAD sha, `git diff --stat <base>..HEAD`, the
118+
verification summary lines and log paths, every deviation from the
119+
contract with its reason, and every open question. The supervisor judges
120+
the slice by its executed result: no regression in the campaign sweep, the
121+
engine closer to an independent backtest + forward-execution state
122+
machine, and Pine-parity behaviour kept in codegen with this kernel clean.

‎CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ add_library(pineforge STATIC
122122
src/timezone.cpp
123123
src/native_calendar.cpp
124124
src/native_run_spec.cpp
125+
src/native_fx_curve.cpp
125126
)
126127

127128
# Canonical alias for downstream find_package(PineForge) consumers.

‎README.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,11 @@ TradingView ties some day-boundary logic (intraday order caps, session rollovers
242242

243243
## Public C ABI
244244

245-
`<pineforge/pineforge.h>` is the single canonical consumer header. Every compiled strategy `.so` exports exactly these 64 symbols and no internal C++ symbol (`-fvisibility=hidden`, `PF_API` on the public set, checked in CI by `scripts/check_c_abi_runtime.py`):
245+
`<pineforge/pineforge.h>` is the single canonical consumer header. It declares
246+
exactly 65 public `PF_API` functions: 57 runtime implementations and eight
247+
per-strategy generated exports. Every compiled strategy `.so` exports that
248+
public set and no internal C++ symbol (`-fvisibility=hidden`, `PF_API` on the
249+
public set, checked in CI by `scripts/check_c_abi_runtime.py`):
246250

247251
| Symbol | Role |
248252
|---|---|
@@ -262,7 +266,7 @@ TradingView ties some day-boundary logic (intraday order caps, session rollovers
262266
| `strategy_set_account_currency_fx_series` | Effective-time quote-to-account FX |
263267
| `strategy_get_last_error` | The latest runtime error |
264268
| `pf_version_get` / `pf_version_string` / `pf_abi_version` | Runtime version, version string, struct-layout version (`PF_ABI_VERSION == 4`) |
265-
| `strategy_execution_contract` / `strategy_configure_native_v1` | Query Legacy vs NativeMarketV1; apply the versioned native run specification |
269+
| `strategy_execution_contract` / `strategy_configure_native_v1` / `strategy_configure_native_fx_curve_v1` | Query Legacy vs NativeMarketV1; apply the versioned native run specification; stage or clear an immutable native FX curve |
266270
| `strategy_request_abort` / `strategy_last_run_status` | Cooperative abort of a run in progress; `0`=completed, `1`=aborted |
267271
| `strategy_set_realtime_tail` | Live-runtime surface (ABI v4): the array's last bar is a still-forming tail — `barstate.islast=false`, `last_bar_index`/`last_bar_time` frozen at the horizon bar, no range-end row |
268272
| `strategy_set_probe_suppress_tail_logic` | ABI v4: the last bar runs only the broker's pre-`on_bar` steps (pending-order settlement, intraday-cap/loss checks) and returns — no `on_bar`, no margin-call / POOC second pass / bracket-reissue processing (the range-end row is `strategy_set_realtime_tail`'s to skip; the flags are independent) |

‎docs/ci.md‎

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ python3 scripts/ci_verify.py release --build-dir build --jobs 4
1919
```
2020

2121
The command runs source guards, configures and rebuilds every enabled target,
22-
prepares the real historical ABI provider, runs CTest, installs the package,
22+
prepares the real historical ABI providers, runs CTest, installs the package,
2323
and builds and runs the `find_package` consumer. The smoke test compares the
2424
installed library's reported version with `VERSION`. After a successful build,
2525
a failing test suite does not hide a separate install or package failure.
@@ -76,17 +76,33 @@ Ordinary CMake builds retain `AUTO`, the existing git-describe-first behavior.
7676
No release tag or VERSION value is rewritten by verification.
7777

7878
The verifier fetches the pinned historical ABI commits `e60e571` (R2),
79-
`0e18690` (selected settlement, before exact reversal), and `c3ed455` (native
80-
host v13) without tags only when each object is missing. It builds all three
81-
full historical static libraries with tests disabled, or validates and reuses
79+
`0e18690` (selected settlement, before exact reversal), `c3ed455` (native
80+
host v13), and `f736676` (native host v14) without tags only when each object
81+
is missing. It builds all four full historical static libraries with tests
82+
disabled, or validates and reuses
8283
their matching prepared receipts under `settlement-abi-base/`,
83-
`settlement-abi-prior/`, and `native-abi-v13/`. Compiler, configuration and
84-
version-source mismatches refuse reuse without deleting the old evidence.
84+
`settlement-abi-prior/`, `native-abi-v13/`, and `native-abi-v14/`. Compiler,
85+
configuration and version-source mismatches refuse reuse without deleting the old evidence.
8586
Each profile needs matching providers; a Mac Release archive cannot replace
8687
a Linux sanitizer build. CTest itself performs no network fetch.
88+
The full settlement matrix uses these four archives plus current v15. Its
89+
host/order matrix rejects cross-epoch links among v13, v14 and v15; the
90+
unchanged driver v4 requires positive links in both v14→v15 and v15→v14
91+
directions. Current-execution callers compile only from v14 and v15 headers.
8792
The [ABI guide](../tests/fixtures/settlement_cpp_abi/README.md) describes the
8893
actual old/new library pairs and their immutable inputs.
8994

95+
CTest writes `settlement-abi-receipt.json` for the five-archive matrix and
96+
`native-abi-receipt.json` for native controls. The native receipt includes the
97+
active `v14_current_execution_shape_agnostic_compile` against the authenticated
98+
frozen v14 tar closure. During native-terms phase 0 through phase 1b,
99+
`CURRENT_TERMS_SURFACE_READY = False` retains the complete
100+
`CURRENT_EXECUTION_V15_CALLER` and `NATIVE_FX_CURVE_CALLER` templates as pending
101+
surface rows. The named good v15 compile and missing-Cancelled compile rejection
102+
also remain pending. Phase 1c activates every row with the actual host surface;
103+
the good caller must compile before its intentional negative compile control.
104+
Ordinary compile failures remain failures, separate from ABI link rejections.
105+
90106
## Failure evidence
91107

92108
Each build directory contains `ci-summary.json` and full command logs under

‎docs/coverage.md‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@
5959

6060
## Public C ABI
6161

62-
`<pineforge/pineforge.h>` is the **single canonical consumer header**.
63-
Every compiled PineForge strategy `.so` exports exactly the 28 symbols
64-
declared there:
62+
`<pineforge/pineforge.h>` is the **single canonical consumer header**. It has
63+
exactly 65 public `PF_API` declarations: 57 runtime implementations and eight
64+
per-strategy generated exports. Every compiled PineForge strategy `.so` exports
65+
that public set. The historical 28-symbol module sentence was not a current
66+
module inventory; the grouped table below is a guide, not the count:
6567

6668

6769
| Symbol | Role |
@@ -90,6 +92,7 @@ declared there:
9092
| `strategy_set_syminfo_pointvalue` | Futures $-per-point multiplier (`syminfo.pointvalue`) |
9193
| `strategy_set_syminfo_metadata` | Inject fundamental / exchange metadata by Pine member name |
9294
| `strategy_set_account_currency_fx_series`| Effective-time quote-to-account conversion curve |
95+
| `strategy_configure_native_fx_curve_v1` | Stage or clear an immutable FX curve on a Ready native handle |
9396
| `strategy_get_last_error` | Error message from the most recent failed run |
9497
| `pf_version_get` | Runtime version (struct) |
9598
| `pf_abi_version` | Caller-allocated POD layout version |
@@ -121,7 +124,7 @@ single `.hpp`):
121124

122125
| Module | Header | Source | Pine-facing role |
123126
| ------------------ | ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
124-
| Public C ABI | `pineforge.h` | `c_abi.cpp` (+ layout `static_assert`s) | The 28 documented C symbols every compiled strategy `.so` exports. |
127+
| Public C ABI | `pineforge.h` | `c_abi.cpp` (+ layout `static_assert`s) | 65 public `PF_API` declarations: 57 runtime implementations plus eight per-strategy generated exports. `strategy_configure_native_fx_curve_v1` stages the additive native FX curve. |
125128
| Engine | `engine.hpp` | `engine_run.cpp`, `engine_stream.cpp`, `engine_orders.cpp`, `engine_fills.cpp`, `engine_path_resolve.cpp`, `engine_strategy_commands.cpp`, `engine_trade_accessors.cpp`, `engine_security.cpp`, `engine_lower_tf.cpp`, `engine_risk.cpp`, `engine_report.cpp` | One-shot and continuous lifecycle, orders, raw-trade/bar fills, risk, reports, inputs / syminfo, magnifier, TF aggregation, and `request.security` plumbing. |
126129
| Engine internals | `engine_internal.hpp` | (private cross-TU header) | `pineforge::internal::`* types and helpers shared between engine `.cpp` partitions; not part of the public ABI. |
127130
| Technical analysis | `ta.hpp` | `ta_moving_averages.cpp`, `ta_oscillators.cpp`, `ta_volatility_trend.cpp`, `ta_extremes_volume.cpp`, `ta_misc.cpp` | Official `ta.`* functions and series variables backed by stateful runtime classes with `compute` / `recompute`, plus `pivot_point_levels(...)` free function. |

0 commit comments

Comments
 (0)