Skip to content

Commit 74bd92a

Browse files
Oscarcodex
andcommitted
feat: add local QuantOS kernel and Codex broker
Add immutable E0 research runs, point-in-time baseline validation, bounded local Codex review, truthful legacy web contracts, and deterministic release gates. Co-Authored-By: Codex <noreply@openai.com>
1 parent 1eab803 commit 74bd92a

52 files changed

Lines changed: 6294 additions & 367 deletions

Some content is hidden

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

.gitattributes

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
* text=auto
2+
*.csv text eol=lf
3+
*.json text eol=lf
4+
*.jsonl text eol=lf
5+
*.md text eol=lf
6+
*.py text eol=lf
7+
*.js text eol=lf
8+
*.toml text eol=lf
9+
*.yml text eol=lf
10+
*.yaml text eol=lf

.github/workflows/python-ci.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ jobs:
1717
- run: python -m pip install --upgrade pip
1818
- run: pip install -e ".[full]"
1919
- run: pytest -q
20-
- run: python scripts/qrae_run_full_v0.py --cycle-id ci_full_cycle
20+
- name: Run and verify deterministic kernel fixture
21+
shell: bash
22+
run: |
23+
run_output="$(python -m qrae.cli run --work-order examples/price_baseline/work_order.json --workspace . --output-root .quantos-ci)"
24+
run_dir="$(python -c 'import json,sys; print(json.load(sys.stdin)["run_dir"])' <<<"$run_output")"
25+
python -m qrae.cli verify --run-dir "$run_dir"
2126
- run: python scripts/qrae_readiness.py --env dev
2227
- uses: actions/upload-artifact@v4
2328
with:
2429
name: qrae-v0-artifacts
25-
path: |
26-
research_base/latest/*
27-
reports/generated/*
30+
path: .quantos-ci/

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.quantos/
2+
.venv/
3+
__pycache__/
4+
*.py[cod]
5+
.pytest_cache/
6+
.ruff_cache/
7+
.mypy_cache/
8+
.coverage
9+
htmlcov/
10+
build/
11+
dist/
12+
*.egg-info/
13+
.env
14+
.env.*
15+
!.env.example
16+
/data/
17+
reports/generated/
18+
*.pem
19+
*.key
20+
*.pfx
21+
*.p12
22+
auth.json

AI_RESUME.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@
66
77
---
88

9+
## 0. Authoritative rebaseline — 2026-07-11
10+
11+
This section supersedes older implementation-status, Vercel-first, cron, and next-sprint claims elsewhere in this historical handoff. Verify every capability against current files and tests.
12+
13+
- The product is now **local-first QuantOS**. Vercel is a legacy/deferred sanitized review surface, not the scheduler, storage truth, quant engine, or authority.
14+
- The current source release candidate is `0.10.0`; the live Vercel surface remains on the older `0.9.x` deployment until a verified deployment replaces it.
15+
- A real deterministic kernel exists in `src/qrae/`: strict work orders, immutable artifacts, hash-chained state, point-in-time price quality, a next-observation after-cost baseline, independent recomputation, evidence/claim/decision/report/knowledge artifacts, and a bounded optional local Codex broker.
16+
- The example fixture and the generic V0 price contract are capped at `E0`. `E1` remains blocked until authenticated data provenance and a registered market adapter exist; no current code produces WFO, event replay, paper, live, or allocator-ready evidence.
17+
- The current source disables public web cron execution and removes Vercel schedules. The live deployment was still serving the older `202 accepted` contract when checked on 2026-07-11; treat it as stale and do not infer that it executes work.
18+
- Codex runs only through an explicit local, shell-free, read-only, schema-bound broker. It starts no listener, receives no trading/cloud-write credential, and cannot promote research state. Disabled/unavailable Codex becomes `DEFERRED_NO_CODEX` while deterministic work continues.
19+
- A local end-to-end broker smoke on 2026-07-11 produced a validated `DRAFT_READY` adversarial critique with `requested_transition=NONE`; this proves the installed Codex CLI boundary, not research quality or deployment readiness.
20+
- `configs/qrae_requirements_traceability.json` was downgraded to evidence-backed statuses and is enforced by `python scripts/qrae_traceability_audit.py --strict`.
21+
- Current executable commands are documented in `README.md` and `docs/LOCAL_KERNEL.md`; older quick-start commands naming missing scripts are obsolete.
22+
- The broad QuantOS remains incomplete. Next implementation gates are real read-only market adapters across registered families, durable local catalog/brain, WFO/statistical/risk modules, event replay for survivors, report factory, and only later optional online adapters/review UI.
23+
24+
---
25+
926
## 1. Project identity
1027

1128
**Project name:** QRAE-RD

README.md

Lines changed: 50 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,89 @@
1-
# QRAE-RD V0
1+
# QRAE QuantOS
22

3-
**QRAE-RD** = **Quant Research Agent Engine — Research Director Architecture**.
3+
QRAE is a local-first, human-gated quantitative research operating system. The repository now contains a real deterministic kernel slice alongside the older staging dashboard.
44

5-
Current implementation tag: **V0.9.0 / official V0 full-cycle staging candidate**.
5+
## Current truth
66

7-
This repository is the official V0 scaffold for the CUHK QTS autonomous, human-gated, agent-orchestrated quantitative research pipeline.
7+
Implemented and tested:
88

9-
## Resume here first
9+
- strict, hash-bound research work orders;
10+
- point-in-time CSV price contracts and data-quality quarantine;
11+
- a delayed-fill lagged-momentum baseline with registered entry/liquidation costs and chronological train/validation/test splits;
12+
- immutable run bundles, atomic latest pointers, and tamper-evident state logs;
13+
- metric/accounting recomputation, evidence ceilings, claim ledgers, decision records, compact reports, and knowledge records;
14+
- an optional local Codex broker with fixed tasks, an isolated read-only permission profile, bounded output, no state-promotion authority, and deterministic no-Codex fallback;
15+
- legacy read-only Vercel dashboard/API views; deployment content may lag this branch and is not execution evidence.
1016

11-
Future AIs and engineers should begin with:
17+
Not yet implemented: production market adapters, remote storage/batch adapters, walk-forward and nested model selection, event-driven replay, portfolio/risk engines, ML challengers, a complete Obsidian brain, allocator-grade report generation, authenticated web review, or any paper/live execution system.
1218

13-
- [`AI_RESUME.md`](AI_RESUME.md) — canonical project handoff containing the user’s requirements, ideas, architecture decisions, safety rules, deployment state, trial outcomes, unresolved gaps, and exact next actions.
19+
The committed dashboard artifacts and legacy synthetic tournament are demonstrations, not evidence that those missing systems ran.
1420

15-
The system is designed around one rule:
21+
## Local quick start
1622

1723
```text
18-
Scripts search and verify.
19-
Cheap/free AI drafts and implements routine tasks.
20-
Strong AI acts as Research Director only for survivors.
21-
Human approves only important decisions.
24+
python -m pip install -e ".[full]"
25+
python -m pytest -q
26+
python -m qrae.cli run --work-order examples/price_baseline/work_order.json --workspace . --output-root .quantos
2227
```
2328

24-
## What this repo contains
25-
26-
- RD-Agent-style specification/synthesis/implementation/validation/analysis loop.
27-
- Multi-asset opportunity tournament: Polymarket, crypto, ETFs, bonds, equities, macro.
28-
- Deterministic quant truth engine: data validation, backtests, walk-forward, risk, scores.
29-
- RD-Agent-compatible score vector: IC, ICIR, Rank IC, Rank ICIR, ARR, IR, MDD, Calmar.
30-
- QRAE extended score vector: OOS Sharpe, WFE, Sortino, Omega, VaR/CVaR, turnover, data quality, overfit penalty.
31-
- Human-gated Research Director packet flow for ChatGPT Plus/Pro or Gemini CLI, plus a deterministic V0 Research Director surrogate so the no-API pipeline can run end-to-end.
32-
- Vercel/GitHub-ready static dashboard, serverless APIs, cron contracts, notification hooks, MCP placeholders.
33-
- Allocator-style report template and CUHK QTS paper plan.
34-
35-
## V0 operating mode
36-
37-
V0 is intentionally **no-paid-API-first**:
29+
The command prints the immutable run directory. Verify it independently:
3830

3931
```text
40-
Vercel/GitHub run automation.
41-
The deterministic Research Director surrogate can run automatically for V0 end-to-end validation.
42-
ChatGPT Plus is still the preferred high-quality reviewer for top packets when human review is desired.
43-
Gemini CLI can be used locally for low-cost implementation tasks.
44-
API automation can be added later through the Research Director adapter.
32+
python -m qrae.cli verify --run-dir .quantos/runs/<run-id>
4533
```
4634

47-
No live trading is enabled in V0.
48-
49-
## Quick start
50-
51-
```bash
52-
python -m venv .venv
53-
source .venv/bin/activate
54-
pip install -e ".[full]"
55-
pytest -q
56-
python scripts/qrae_readiness.py --env dev
57-
python scripts/qrae_run_cycle.py --cycle-id local_cycle
58-
python scripts/qrae_run_full_v0.py --cycle-id local_full_cycle
59-
python scripts/qrae_smoke.py --pytest
60-
python scripts/run_demo.py
61-
python scripts/qrae_task_pack.py --example
62-
npm ci
63-
npm run typecheck
64-
npm run build
65-
```
35+
The bundled dataset is synthetic and its work order is capped at `E0`. It proves mechanics and artifact integrity only.
6636

67-
The deterministic cycle creates ranked idea cards, a latest digest, and a Research Director packet.
37+
## Local Codex review
6838

69-
## V0 dev/prod posture
39+
Codex is optional and never owns metrics or state transitions. Prepare a fixed review task from a verified run:
7040

71-
Use the included readiness checker before promotion:
41+
```text
42+
python -m qrae.cli codex-prepare --run-dir .quantos/runs/<run-id> --task-id critic-001 --task-kind ADVERSARIAL_CRITIC
43+
```
7244

73-
```bash
74-
python scripts/qrae_readiness.py --env dev
75-
python scripts/qrae_readiness.py --env staging
76-
python scripts/qrae_readiness.py --env prod
45+
Without an explicit enable flag, execution records a safe `DEFERRED_NO_CODEX` result:
46+
47+
```text
48+
python -m qrae.cli codex-run --work-order .quantos/codex-work-orders/<run-id>/critic-001.json --workspace .quantos
7749
```
7850

79-
`dev` is expected to pass without external services. `staging` is designed to pass without external paid services for V0 preview validation. `prod` intentionally requires database/artifact/notification configuration before it passes. Live trading and automated LLM execution remain disabled in V0.
51+
To invoke the locally authenticated Codex CLI, repeat with `--enable-codex`. The broker uses a fixed `codex exec` argument vector, hash-checked stdin evidence, an isolated read-only permission profile, disabled action tools/integrations, ignored user config/rules, a strict output schema, streaming time/output bounds, a sanitized environment, and an immutable outbox. It starts no listener and receives no trading or cloud-write credentials.
8052

81-
## Recommended GitHub/Vercel setup
53+
## Architecture posture
8254

83-
1. Push this repository as the initial commit.
84-
2. Import the repo into Vercel.
85-
3. Use `Other` framework preset, `npm ci`, `npm run build`, output `public`.
86-
4. Add `QRAE_ENVIRONMENT=staging` and `QRAE_DISABLE_AUTOMATED_LLM=true`.
87-
5. Add Postgres/Neon, Blob/S3/R2, and Resend later for production.
88-
6. Connect GitHub to ChatGPT for repo reading.
89-
7. Add QRAE MCP connector later for dashboard/artifact access inside ChatGPT.
55+
- Canonical research state, private alpha, artifacts, and decisions are local.
56+
- Optional online services may later fetch, store, or batch-process bounded data through hash-verified adapters.
57+
- Vercel is a deferred sanitized review surface, not the scheduler, database, quant engine, or authority.
58+
- Research code has no live-order path. Paper, shadow, and live execution require a separate approved OMS/risk/reconciliation system.
59+
- Data and deterministic artifacts own facts; validators own hard gates; humans own publication, exceptional risk, and capital.
9060

91-
## Human workflow
61+
## Repository map
9262

9363
```text
94-
1. Configure research universes and schedules.
95-
2. Let daily/weekly workflows generate ideas, backtests, WFO, risk, scores.
96-
3. Receive Gmail notification only when candidates survive.
97-
4. Copy Research Director packet into ChatGPT Plus/Pro.
98-
5. Paste the decision back into QRAE.
99-
6. System queues deepen/revise/reject/report action.
64+
src/qrae/ deterministic contracts, kernel, state, artifacts, baseline, Codex broker
65+
tests/ positive and negative deterministic tests
66+
examples/price_baseline/ synthetic E0 work order and price fixture
67+
scripts/qrae_run_cycle.py compatibility wrapper for the local kernel
68+
api/ and public/ legacy read-only Vercel review surface
69+
configs/ legacy runtime, quality, and traceability configuration
70+
research_base/latest/ committed legacy demonstration artifacts
10071
```
10172

102-
## Docs
73+
## Documentation
10374

104-
- [`AI_RESUME.md`](AI_RESUME.md)
75+
- [`docs/LOCAL_KERNEL.md`](docs/LOCAL_KERNEL.md)
10576
- [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md)
106-
- [`docs/RESEARCH_METHODOLOGY.md`](docs/RESEARCH_METHODOLOGY.md)
10777
- [`docs/QUALITY_GATES.md`](docs/QUALITY_GATES.md)
10878
- [`docs/REQUIREMENTS_TRACEABILITY.md`](docs/REQUIREMENTS_TRACEABILITY.md)
109-
- [`docs/CUHK_QTS_PAPER_PLAN.md`](docs/CUHK_QTS_PAPER_PLAN.md)
110-
- [`AGENTS.md`](AGENTS.md)
111-
- [`PROJECT_CONTEXT.md`](PROJECT_CONTEXT.md)
79+
- [`AI_RESUME.md`](AI_RESUME.md) — historical handoff; verify claims against files and tests.
11280

11381
## Safety status
11482

11583
```yaml
84+
local_canonical_state: true
11685
live_trading: false
117-
automated_paid_llm: false
118-
source_of_truth: deterministic_artifacts
86+
public_codex_endpoint: false
87+
codex_state_promotion: false
11988
human_capital_gate_required: true
12089
```

api/_qrae.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ function readJson(relativePath, fallback) {
1313
}
1414

1515
const runtimeConfig = readJson('configs/qrae_runtime.json', {});
16-
const VERSION = runtimeConfig.version || '0.9.0';
16+
const VERSION = runtimeConfig.version || '0.10.0';
1717
const GENERATED_AT = '2026-07-05T00:00:00.000Z';
1818

1919
const qraeRuntime = {
2020
system: 'QRAE-RD',
2121
version: VERSION,
22-
mode: runtimeConfig.mode || 'v0.9-human-gated-plus-deterministic-director-surrogate',
22+
mode: runtimeConfig.mode || 'v0.10-local-first-e0-kernel',
2323
environment: process.env.QRAE_ENVIRONMENT || process.env.VERCEL_ENV || 'local',
2424
liveTradingEnabled: false,
25-
automatedLlmEnabled: process.env.QRAE_DISABLE_AUTOMATED_LLM !== 'false' ? false : true,
26-
directorMode: process.env.QRAE_DISABLE_AUTOMATED_LLM === 'false' ? (runtimeConfig.directorModeWhenAutomated || 'api-adapter-optional') : (runtimeConfig.directorModeWhenManual || 'manual-chatgpt-plus-or-deterministic-surrogate'),
25+
automatedLlmEnabled: false,
26+
directorMode: runtimeConfig.directorModeWhenManual || 'optional-local-codex-cli',
2727
sourceOfTruth: 'deterministic-artifacts-not-llm-text',
2828
};
2929

@@ -51,7 +51,7 @@ const qraeScoreVector = [
5151
const dashboardCards = runtimeConfig.dashboardCards || [
5252
{ title: 'Health', href: '/api/health', body: 'Runtime and safety state.' },
5353
{ title: 'Research status', href: '/api/research/status', body: 'Enabled universes, integrations, and V0 governance.' },
54-
{ title: 'Latest digest', href: '/api/research/latest', body: 'Latest research digest contract for dashboards and ChatGPT packets.' },
54+
{ title: 'Legacy digest', href: '/api/research/latest', body: 'Committed review snapshot with no freshness guarantee.' },
5555
];
5656

5757
function json(res, payload, status = 200) {

api/cron/daily-research.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@ const { json, methodGuard, basePayload } = require('../_qrae');
22
module.exports = function handler(req, res) {
33
if (!methodGuard(req, res)) return;
44
json(res, basePayload({
5-
status: 'accepted',
5+
status: 'disabled',
66
workflow: 'daily-research',
7-
mode: 'v0-python-worker-contract',
8-
trigger: 'cron-or-manual',
9-
actions: [
10-
'refresh latest data adapters',
11-
'run data-quality gates',
12-
'generate/score idea cards',
13-
'auto-reject weak candidates',
14-
'write artifacts for survivor packets',
15-
],
16-
nextStep: 'Run scripts/qrae_run_cycle.py in the worker/CI environment for deterministic artifact generation.',
17-
}), 202);
7+
mode: 'local-only-disabled',
8+
actions: [],
9+
reason: 'Public web scheduling is disabled. Run the verified local QuantOS CLI; this endpoint cannot queue or execute research.',
10+
liveTradingEnabled: false,
11+
}), 410);
1812
};

api/cron/weekly-director-packet.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@ const { json, methodGuard, basePayload } = require('../_qrae');
22
module.exports = function handler(req, res) {
33
if (!methodGuard(req, res)) return;
44
json(res, basePayload({
5-
status: 'accepted',
5+
status: 'disabled',
66
workflow: 'weekly-director-packet',
7-
mode: 'manual-research-director-gate',
8-
actions: [
9-
'compile survivor candidates',
10-
'build Research Director packet',
11-
'notify Gmail/Resend when configured',
12-
'wait for human/strong-model decision',
13-
],
7+
mode: 'local-only-disabled',
8+
actions: [],
9+
reason: 'Public web scheduling is disabled. Prepare and review packets through the local QuantOS CLI.',
1410
liveTradingEnabled: false,
15-
}), 202);
11+
}), 410);
1612
};

api/director/latest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ module.exports = function handler(req, res) {
77
decisionAvailable: Boolean(decision),
88
decision,
99
markdown,
10-
note: 'This is the deterministic Research Director surrogate output. Treat as a plan; metrics remain artifact-grounded.',
10+
note: 'Committed legacy demonstration only; it is not a current local-kernel decision or freshness proof.',
1111
}));
1212
};

api/health.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
const { json, methodGuard, basePayload, safetyRules } = require('./_qrae');
22
module.exports = function handler(req, res) {
33
if (!methodGuard(req, res)) return;
4-
json(res, basePayload({ status: 'ok', safetyRules }));
4+
json(res, basePayload({
5+
status: 'legacy_review_surface',
6+
canonicalState: 'local',
7+
publicResearchExecutionEnabled: false,
8+
safetyRules,
9+
}));
510
};

0 commit comments

Comments
 (0)