Files
encyclopedia-knowledge-graph/docs/plans/active/PLAN-QUANT-PRE-MARKET-OPEN-DAILY-BRIEF-AND-REGIME-CADENCE.md
T

253 lines
18 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# PLAN: Pre-Market-Open Daily Portfolio & Memetic Regime Update Generation Cadence for Panel 6 (`PLAN #72`)
**Document ID:** `PLAN-QUANT-PRE-MARKET-OPEN-DAILY-BRIEF-AND-REGIME-CADENCE`
**Status:** `IMPLEMENTED (docs/plans/active/ — Pending Archive Rotation)`
**Target Ecosystem Version:** `v2.18.0` (Baseline: `v2.17.1`)
**Target Repositories:** `hyperstitionstudio-core`, `encyclopedia-knowledge-graph`
**Target Surface:** `/quant/index.html` (`PANEL-P06.DAILY_BRIEF`, `#dailyBriefPanel`)
**Web Route:** `https://hyperstitionstud.io/graph/docs/plans/active/PLAN-QUANT-PRE-MARKET-OPEN-DAILY-BRIEF-AND-REGIME-CADENCE.pdf`
**Author:** m00t & Hermes Agent
**Date:** 2026-12-02
---
## 1. Executive Summary & Operational Objective
### 1.1 Objective
Establish an automated, verified, and idempotent production schedule to generate and serve the quantitative **"Daily Portfolio & Memetic Regime Update"** on quant page **`PANEL-P06.DAILY_BRIEF`** (`#dailyBriefPanel`) strictly **prior to every US market cash equity open** (09:30 AM US Eastern Time, corresponding to 14:30 UTC in EST / 13:30 UTC in EDT).
### 1.2 Motivation & Information Asymmetry Advantage
Currently, quantitative data production on `hyperstitionstud.io` executes across two primary windows:
1. **Closing-Bell Window (`21:30 UTC` Mon–Fri):** Ingests regular exchange daily closing bars and post-close prices.
2. **Midnight Rollover Window (`00:00 UTC` Daily):** Calibrates daily calendar rolls, Ingglish phonetic CI tier provisions, and 24-hour crypto turnover.
While these runs capture the closing record of prior days, market participants inspecting `PANEL-P06.DAILY_BRIEF` at 09:00–09:25 AM US Eastern Time prior to the opening bell currently view the prior day's closing brief. Introducing a dedicated **Pre-Market-Open Generation Cadence** guarantees that:
- Fresh **08:30 AM ET macroeconomic releases** (CPI, PPI, PCE, Non-Farm Payrolls, Initial Jobless Claims, GDP revisions) published via Federal Reserve FRED feeds are ingested.
- Overnight European market moves, Asian session closes, and 24/7 cryptocurrency volatility (BTC, SOL, ETH) are fully incorporated into market priors.
- Overnight US equity index futures (ES, NQ) pre-market sentiment informs the 3-state Bayesian likelihood estimation across:
- `REGIME-R01.BULL_RISK_ON` (Risk-On Expansion & Trend Continuation)
- `REGIME-R02.PINNED_ISOMETRIC` (Isometric Attractor Pinning & Dose 2 Variance Compression)
- `REGIME-R03.TAIL_DRAWDOWN` (Tail Drawdown & Dose 3+ Breakout Shock)
- Daily testable macro questions $Q_t$ and falsification conditions are published before any order execution occurs in cash equity markets.
---
## 2. VPS Job Execution Architecture: Prioritizing Existing Automation
The core directive specifies: **"Use existing VPS cron jobs, creating a new one as a last resort."**
### 2.1 Audit of Existing VPS Scheduling Infrastructure
Hyperstition Studio operates three existing automation channels on the production VPS (`hyperstitionstud.io`):
1. **`hyperstition-closing-bell-harvest.timer` (`Mon..Fri 21:30:00 UTC`):** Invokes `run-vps-data-production.sh --window=us-closing-bell`.
2. **`hyperstition-utc-rollover-harvest.timer` (`Daily 00:00:00 UTC`):** Invokes `run-vps-data-production.sh --window=utc-rollover`.
3. **`hyperstition-archive-rotate.timer` & `/etc/cron.d/hyperstition-archive-rotate` (`Daily 00:20:00 UTC`):** Invokes `run-vps-archive-rotation.sh`.
### 2.2 Schedule Execution Strategy Hierarchy
```
Existing Automation Infrastructure Evaluation
+----------------------------------------------------------------------------------------------------+
| [Strategy A — RECOMMENDED FIRST RESORT] |
| Multi-Calendar Trigger in Existing hyperstition-closing-bell-harvest.timer Unit |
| - Uses native systemd multi-OnCalendar capability: |
| OnCalendar=Mon..Fri *-*-* 14:00:00 UTC |
| OnCalendar=Mon..Fri *-*-* 21:30:00 UTC |
| - Parameterizes hyperstition-closing-bell-harvest.service with --window=auto |
| - ZERO new systemd service or timer unit files created |
+----------------------------------------------------------------------------------------------------+
|
(If Strategy A is bypassed)
v
+----------------------------------------------------------------------------------------------------+
| [Strategy B — SECOND RESORT] |
| Cron Multiplexing in Existing /etc/cron.d/hyperstition-archive-rotate |
| - Appends pre-market harvest rule to existing tracked deploy/cron.d/hyperstition-archive-rotate: |
| 0 14 * * 1-5 root /srv/.../run-vps-data-production.sh --window=us-pre-market-open |
| - ZERO new cron files or systemd units created; reuses existing deploy/sync-vps-repos.sh sync pass |
+----------------------------------------------------------------------------------------------------+
|
(If Strategies A & B bypassed)
v
+----------------------------------------------------------------------------------------------------+
| [Strategy C — STRICT LAST RESORT] |
| Dedicated hyperstition-pre-market-harvest.{service,timer} Pair |
| - Proves necessary only if operational policies strictly forbid multi-calendar systemd timers |
| - Installs 2 net-new unit files in deploy/ and /etc/systemd/system/ |
+----------------------------------------------------------------------------------------------------+
```
#### Strategy A (Recommended First Resort): Dual-Calendar Existing Systemd Timer
- **Mechanism:** In systemd, a single `.timer` unit accepts multiple `OnCalendar=` declarations. We modify `deploy/hyperstition-closing-bell-harvest.timer` by adding:
```ini
[Timer]
OnCalendar=Mon..Fri *-*-* 14:00:00 UTC
OnCalendar=Mon..Fri *-*-* 21:30:00 UTC
Persistent=true
RandomizedDelaySec=15
Unit=hyperstition-closing-bell-harvest.service
```
- **Dynamic Window Resolution in `run-vps-data-production.sh`:**
Update `run-vps-data-production.sh` to support `--window=auto`. When invoked with `--window=auto` (or when unset):
- If current UTC hour is `13` or `14` (`09:00–09:30 EST`): resolves to `WINDOW_MODE="us-pre-market-open"`.
- If current UTC hour is `21` or `22` (`16:30–17:30 EST`): resolves to `WINDOW_MODE="us-closing-bell"`.
- If current UTC hour is `00` (`19:00 EST / 20:00 EDT`): resolves to `WINDOW_MODE="utc-rollover"`.
- **Zero Overhead:** Requires `0` new service units, `0` new timer files, and `0` changes to deployment script unit enumeration.
#### Strategy B (Second Resort): Multiplexing Within Existing `/etc/cron.d/` File
- **Mechanism:** Hyperstition Studio already tracks and deploys `/etc/cron.d/hyperstition-archive-rotate` via `deploy/sync-vps-repos.sh`.
- We add the weekday 14:00 UTC pre-market harvest command directly into this existing cron definition:
```cron
# /etc/cron.d/hyperstition-archive-rotate
# 00:20 UTC: Daily cold-archive rotation and SQLite check
20 0 * * * root /srv/hyperstitionstud.io/repos/hyperstitionstudio-core/deploy/run-vps-archive-rotation.sh >> /var/log/hyperstition-archive-rotate.log 2>&1
# 14:00 UTC (09:00 EST Mon-Fri): Pre-market-open daily brief & macro harvest
0 14 * * 1-5 root /srv/hyperstitionstud.io/repos/hyperstitionstudio-core/deploy/run-vps-data-production.sh --window=us-pre-market-open >> /var/log/hyperstition-pre-market.log 2>&1
```
- **Evaluation:** Retains single-file cron maintenance; avoids creating new cron configuration files.
#### Strategy C (Strict Last Resort): Dedicated Pre-Market Unit Pair
- If both Strategy A and B are deemed unviable by operations, provision:
- `deploy/hyperstition-pre-market-harvest.service`
- `deploy/hyperstition-pre-market-harvest.timer` (`OnCalendar=Mon..Fri *-*-* 14:00:00 UTC`)
- Wire into `sync-vps-repos.sh` systemd unit loop and `DEPLOY-GATE-D04` verification.
---
## 3. Data Pipeline & Pipeline Integrity Guarantees
### 3.1 Five-Stage Execution Sequence (`run-vps-data-production.sh`)
When triggered at `14:00 UTC` (`us-pre-market-open`), the orchestrator executes:
```
Stage 1 (Harvest)
├── hs-quant-harvest (--mode us-pre-market-open --append-history --live)
└── hs-macro-harvest (live FRED CSV pulls for 08:30 ET releases)
│
v
Stage 2 (Compilers & Lens Projection)
├── quant.timeseries (recomputes 14-point bidirectional census & dose classifications)
├── hs-daily-brief (builds 5-agenda brief payload, computes IPLD CIDv1, writes JS/JSON)
└── build_encyclopedia_knowledge_graph.py --verify-only
│
v
Stage 3 (Transactional Verification & Rollback)
├── hs-doctor (environment & font checks)
├── ReadOnlyIsolationGuard (asserts zero mutation of core dictionaries)
└── tests/test_core_suite.py
│
[Pass] ──────────────────────────┐
│ │ [Fail]
v v
Stage 4 (RAM Webroot Hydration) Automatic Git Rollback
└── sync-vps-repos.sh git checkout -- .
(--no-pull --no-caddy) Zero tmpfs corruption
│
v
Stage 5 (Source Control Cadence)
└── git commit & push to git.libre.audio
```
### 3.2 Stage 1 Pre-Market Harvest Semantics (`collector.py`)
- **Equities & ETFs:** Daily exchange bars for the current day have not yet printed. The collector verifies that all historical daily bars up to the previous completed closing bell exist and are valid. Intraday pre-market indications (futures gaps, overnight prints) update current session context without synthesizing incomplete daily candles (`PLAN-GATE-G01.EXTANT_DATA`).
- **FRED Macro Series (`macro.py`):** Pulls fresh morning releases published at 08:30 AM ET (Initial Jobless Claims on Thursdays, monthly CPI/PPI releases). If no new data has been released, extant series values remain untouched with zero forward-fill interpolation.
- **Crypto & 24/7 Assets:** Ingests live 24-hour volume and percentage changes across BTC, ETH, and SOL, providing immediate liquidity context for market risk appetite.
---
## 4. Archiving & Historical Ledger Considerations
### 4.1 State Ledger Deduplication & Session Windows (`daily_brief.py`)
Currently, `daily_brief.py` maintains an append-only rolling history in `ingglish-aq-archive/data/daily-brief-state.json`. Lines 463–478 deduplicate entries using a calendar-day match (`generated_at_utc[:10]`) combined with identical posterior probabilities:
```python
# Current deduplication vulnerability:
cur_dt_10 = str(brief_payload["generated_at_utc"])[:10]
if dedup_history and dedup_history[-1].get("generated_at_utc")[:10] == cur_dt_10 and dedup_history[-1].get("posterior_probabilities") == cur_post:
dedup_history[-1] = entry # Overwrites earlier same-day run!
```
**Required Architectural Enhancement:**
1. **Explicit Session Window Tagging:** Introduce `session_window` (`"us-pre-market-open"`, `"us-closing-bell"`, or `"utc-rollover"`) in each history entry:
```json
{
"run_number": 42,
"session_window": "us-pre-market-open",
"generated_at_utc": "2026-12-03T14:00:15Z",
"posterior_probabilities": {
"R1_BULL_RISK_ON": 0.285,
"R2_PINNED_ISOMETRIC": 0.540,
"R3_TAIL_DRAWDOWN_RISK_OFF": 0.175
},
"question_id": "Q-RUN-0042",
"cidv1": "bafkreia..."
}
```
2. **Distinct Session Deduplication:** Allow up to two entries per weekday (one pre-market-open, one closing-bell). A pre-market run will never be overwritten by the post-closing run, establishing a transparent historical record comparing pre-open predictions against closing reality.
3. **Rolling Window Expansion:** Expand `run_history` retention from 30 runs to 60 runs in `daily-brief-state.json`, preserving a full 30 trading days of morning/evening paired Bayesian updates.
### 4.2 Cold-Storage Plan & Telemetry Archive Integration (`hs-archive-rotate`)
- **Quiescent SQLite Telemetry Rotation:** In `run-vps-archive-rotation.sh`, `sqlite_meta.py --ingest-caddy-route-counts` and `--compress-archive --truncate-quiescent --max-mb 100` continue to run at `00:20 UTC`. The database logs all historical daily brief payloads, Indexed by IPLD `cidv1` and timestamp, providing instant historical lookup via `hs_query_workspace_catalog_and_release_state`.
- **Zero Raw JSON Bloat in Git:** Detailed historical archives reside in `.cache/hyperstition-meta.db` (compressed and logrotated) rather than accumulating hundreds of loose daily JSON snapshot files in repository trees.
---
## 5. Compression Standards & Optimization Guarantees
### 5.1 Single-Layer (`1x`) Compression Enforcement
In strict compliance with `PLAN-SINGLE-LAYER-COMPRESSION-ENFORCEMENT-AND-MULTI-COMPRESSED-FILE-REMEDIATION` (`PLAN #55`), every compressed artifact must adhere to the single-compression invariant:
- **Zero Double-Compression:** Never generate `.gz.gz`, `.tar.gz` containing `.gz`, or `.br.gz` sidecars.
- **Logrotate Integrity:** Ensure logrotate rules for `/var/log/hyperstition-pre-market.log` use `nocompress` or standard non-duplicating single-layer rotation.
### 5.2 Tmpfs RAM Webroot Pre-Compression Pass
During Stage 4 (`sync-vps-repos.sh --no-pull --no-caddy`):
- `daily-brief-latest.json` and `daily-brief-data.js` are copied to the tmpfs RAM webroot at `/var/www/hyperstitionstud.io/repos/hyperstitionstudio-core/site/quant/`.
- Pre-compression utilities run in parallel:
- `gzip -9 -k -f daily-brief-data.js` -> `daily-brief-data.js.gz`
- `brotli -q 11 -k -f daily-brief-data.js` -> `daily-brief-data.js.br`
- Caddy serves `.br` and `.gz` static pre-compressed files directly to browser clients with zero dynamic compression CPU cycles.
---
## 6. Git Repository Commit Cadence & Telemetry Reconciliation
### 6.1 Multi-Session Commit Cadence Analysis
Adding a pre-market harvest introduces a third potential automated commit window:
1. `14:00 UTC` Mon–Fri: `chore(telemetry): automated VPS us-pre-market-open harvest (<STAMP_UTC>)`
2. `21:30 UTC` Mon–Fri: `chore(telemetry): automated VPS us-closing-bell harvest (<STAMP_UTC>)`
3. `00:00 UTC` Daily: `chore(telemetry): automated VPS utc-rollover harvest (<STAMP_UTC>)`
Total commit volume: 3 automated commits per weekday, 1 commit per weekend day (~17 automated commits per week across `hyperstitionstudio-core`, `ingglish-hyperdope-gematria`, and `encyclopedia-knowledge-graph`).
### 6.2 Commit Governance & Invariants
1. **Dirty-Check Invariant (`git diff --cached --quiet`):** Automated commits are created strictly when substantive data updates occur. If market holidays or quiet sessions produce zero delta, zero commits are generated.
2. **Lossless Snapshot & Reconcile (`DEPLOY-GATE-D04`):** When developers push code via `/workspace/push-all-to-git-libre-audio.sh` or when VPS timers execute, the system executes:
- `python3 -m hyperstitionstud_io.quant.collector --snapshot-telemetry <tmp_dir>` before `git reset --hard origin/main`.
- `python3 -m hyperstitionstud_io.quant.collector --reconcile-telemetry <tmp_dir>` after reset.
This guarantees that pre-market harvest data on the VPS is never lost or conflicted when production code updates are deployed.
3. **Commit History Hygiene & Retention Cadence:**
Telemetry commits are isolated to specific data files (`site/quant/real-market-history.json`, `site/quant/daily-brief-data.js`, `site/quant/daily-brief-latest.json`, `ingglish-aq-archive/data/*`). Code files are never modified by automated telemetry jobs.
---
## 7. Stepwise Verification Gates & Acceptance Criteria
| Gate ID | Domain | Assertion / Check | Target Command |
| :--- | :--- | :--- | :--- |
| `PLAN-GATE-G01.EXTANT_DATA` | Quant Pipeline | Zero synthetic data; no forward-filled daily bars or fake market prices | `collector.py` & `timeseries.py` invariants |
| `PLAN-GATE-G02.ZERO_LLM` | Autonomous Run | Zero LLM token consumption and zero external LLM API dependencies | `unset OPENROUTER_API_KEY OPENAI_API_KEY` in runner |
| `PLAN-GATE-G03.EROFS_SAFE` | Container/VPS | Strict read-only isolation across taxonomy, glossary, and core directories | `ReadOnlyIsolationGuard` audit receipt verification |
| `PLAN-GATE-G04.EXPORTABLE` | Panel 6 UI | Pre-market brief renders cleanly in `#dailyBriefPanel` with IPLD CIDv1 badge | Browser smoke check on `/quant/index.html` |
| `DEPLOY-GATE-D01.MIRROR_PARITY` | Deployment | Parity between `/workspace` and `hyperstitionstudio-core/deploy` mirrors | `hs-deploy-scripts-sync --check` |
| `DEPLOY-GATE-D04.LOSSLESS_TELEMETRY` | Telemetry Sync | Snapshot and reconciliation passes cleanly with zero clobbered bars | `collector.py --snapshot-telemetry` & `--reconcile-telemetry` |
| `STYLE-GATE-S01.NO_SLATE_BG` | Frontend Style | Panel 6 adopts Group 3 Basalt Chamfer styling (`hs-group3-basalt-chamfer.css`) | `tests/test_core_suite.py` regression suite |
---
## 8. Implementation Rollout Sequence
When approved for implementation, execution proceeds in 4 orderly steps:
1. **Update `run-vps-data-production.sh`:** Add support for `--window=us-pre-market-open` and `--window=auto` time-of-day dispatch.
2. **Enhance `daily_brief.py`:** Add `session_window` attribution and separate morning vs evening deduplication keys, expanding rolling history to 60 runs.
3. **Configure VPS Scheduling (Strategy A or B):** Extend `deploy/hyperstition-closing-bell-harvest.timer` with `14:00:00 UTC` calendar entry (or update `deploy/cron.d/hyperstition-archive-rotate`).
4. **Deploy & Verify:** Run `hs-deploy-scripts-sync --stage`, verify test suite via `tests/test_core_suite.py`, commit and prepare deployment scripts for operator execution.