Skip to content

feat(lean): native LEAN CLI engine executor + LEAN GUI surface - #1256

Open
bishallllllll wants to merge 13 commits into
TraderAlice:devfrom
bishallllllll:feat/lean-integration
Open

feat(lean): native LEAN CLI engine executor + LEAN GUI surface#1256
bishallllllll wants to merge 13 commits into
TraderAlice:devfrom
bishallllllll:feat/lean-integration

Conversation

@bishallllllll

Copy link
Copy Markdown

What

Completes the LEAN/QuantConnect integration on feat/lean-integration (rebased onto current dev, +13 commits) after a full Codex session that ended mid-verification. Two batches:

1. Managed backtests now execute through the native lean CLI

  • LeanService.runBacktest scaffolds a per-run project (lean.json + algorithm) under data/lean/runs/<id>/project and invokes lean backtest . --output <results> when the CLI is installed; the existing Docker runner remains the automatic fallback for CLI-less environments.
  • Results parser upgraded to the current LEAN output shape (lowerCamel keys, array chart points, totalPerformance.{trade,portfolio}Statistics, order symbol.value) with full backward compatibility for the classic PascalCase shape; the summary Statistics dict is merged over the full result so orders/charts/stats all parse.
  • Timeout handling kills the CLI and sweeps engine containers by image + creation window — verified live: zero orphaned containers.
  • Non-zero engine exits with real results classify as completed with a data-quality note instead of failed.
  • quant-lab skill documents the executor.

2. Native LEAN CLI surface + LEAN GUI rename (from the Codex session)

  • checkLeanCli() probe → /api/lean/config, /api/lean/status (leanCliAvailable/Version/Error); new leanStatus tool backs alice-quant system status.
  • Chat workspace instruction lists the native lean CLI next to alice-quant; quant-lab skill bundled for every tool-bearing workspace (context injector).
  • Visible UI chrome renamed Quant Lab → LEAN GUI (tabs, pages, sidebar, nav, en/ja/zh/zh-Hant) with stable quant-lab route IDs intact.
  • CLI export manifests (alice-quant --help) describe the renamed surface.
  • Subprocess log capture fixed to retain stdout/stderr after stream end (LEAN failures keep their evidence).

Verification

  • npx tsc --noEmit ✓ · cd ui && npx tsc -b ✓ · full pnpm test: 5334 passed / 0 failed
  • Live engine smokes on this machine (42.4GB quantconnect/lean:latest, lean 1.0.229):
    • completed run: 29 orders, 14 closed trades, 10 charts, stats parsed to summary.json
    • engine error path (strategy exception) captured with full logs ✓
    • non-zero exit with results → completed + data-quality note ✓
    • timeout → process killed + engine container swept, no orphans ✓
  • UI semantic color audit + ui-layout catalog fixed for the new surface.

Environment notes

  • Fedora SELinux enforcing blocks Docker bind-mounts; data/lean + ~/.lean/tmp are labeled container_file_t via semanage fcontext on this machine.
  • agent-probe.spec.ts fails when ANTHROPIC_API_KEY/ANTHROPIC_BASE_URL are set in the ambient environment (SDK env leak); passes with them unset. Pre-existing, unrelated to LEAN (also seen in the earlier session).

LEAN Integration and others added 13 commits August 30, 2026 16:10
- src/domain/lean/: full adapter layer (types, config-gen, data-converter,
  results, service, algorithms, experiments, journal, research-integrity/)
- src/tool/lean.ts: 8 typed AI tools registered via ToolCenter
- src/webui/routes/lean.ts: REST API for Quant Lab (/api/lean/*)
- ui/src/api/lean.ts: typed frontend API client
- ui/src/pages/: QuantLabPage, StrategyDetailPage, BacktestResultsPage,
  ResearchIntegrityPage, TradeJournalPage
- ui/src/components/lean/: LeanEquityCurve, BacktestMetricsGrid,
  ResearchIntegrityCards, QuantLabSidebar, TradeLogTable
- Python QCAlgorithm templates: ema-cross.py, london-breakout.py, rsi-mean-reversion.py
- Evidence-first research integrity: oos.ts, walk-forward.ts, monte-carlo.ts,
  sensitivity.ts, data-snooping.ts
- 30+ unit tests in src/domain/lean/__tests__/

Additive only: 6 existing files modified with ~50 lines of additive hooks.
Zero deletions. lean.enabled: false by default.
Quant Lab gated — disabled state shown until lean.enabled: true.
LeanService now executes backtests with the QuantConnect lean CLI
(lean backtest <project> --output ...) when the binary is installed,
scaffolding a per-run project (lean.json + algorithm) under
data/lean/runs/*/project. Engine results (orders, charts, stats,
closed trades) are parsed from the current LEAN output shape with a
backward-compatible dual-format parser; the summary statistics dict is
merged over the full result. Timed-out runs kill the CLI and sweep
engine containers by image + creation window so nothing is orphaned.
A Docker-based runner remains as the automatic fallback for machines
without the lean CLI. The quant-lab skill now documents the executor.
…LEAN GUI

The native QuantConnect lean CLI is now a first-class surface: a
checkLeanCli probe feeds /api/lean/config and /api/lean/status, the
new leanStatus tool backs 'alice-quant system status', and the Chat
workspace instruction lists the lean CLI next to alice-quant with a
quant-lab playbook row. Visible UI chrome (tab titles, page headers,
sidebar, navigation labels and all four locale catalogs) reads LEAN
GUI while stable quant-lab route IDs remain unchanged. quant-lab is
also bundled with every tool-bearing workspace via the CLI skills
injector, and the CLI export manifests describe the renamed surface.
Replaces literal palette hex values and palette utility classes
(emerald/blue/purple/amber variants) in the LEAN UI with the semantic
chart tokens and success/warning/destructive roles so every palette
card renders consistently. Keeps the semantic color contract audit
green and updates the ui-layout catalog expectation for the quant-lab
entry.
Copilot AI lite review requested due to automatic review settings August 30, 2026 12:03
@vercel

vercel Bot commented Aug 30, 2026

Copy link
Copy Markdown

@luokerenx4 is attempting to deploy a commit to the luokerenx4's Team Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR completes the QuantConnect LEAN integration by adding a full /api/lean/* WebUI backend plus a “LEAN GUI” frontend surface (while keeping the stable /quant-lab route IDs), and wires the feature into workspace tooling via the alice-quant CLI and quant-lab skill injection.

Changes:

  • Add LEAN WebUI routes for config/status plus templates, strategies, backtests, experiments/optimization, integrity, journal, and data ingest.
  • Add the “LEAN GUI” UI surface (navigation, tab registry/routing, layout defaults, and i18n labels) anchored at /quant-lab.
  • Bundle “quant-lab” as a tool-bearing workspace skill and add alice-quant CLI launchers.

Reviewed changes

Copilot reviewed 156 out of 161 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
ui/src/tabs/UrlAdopter.tsx Adds /quant-lab/* routes and maps quant-lab view specs into the correct activity section.
ui/src/tabs/types.ts Extends ViewSpec and ActivitySection to include quant-lab view kinds.
ui/src/tabs/registry.tsx Registers quant-lab view modules and maps them to pages/titles/URLs.
ui/src/live/ui-layout.ts Adds quant-lab into the default UI layout (Beta group).
ui/src/live/ui-layout.spec.ts Updates layout expectations to include quant-lab.
ui/src/i18n/locales/en.ts Adds “LEAN GUI” nav label for quant-lab.
ui/src/i18n/locales/ja.ts Adds “LEAN GUI” nav label for quant-lab.
ui/src/i18n/locales/zh.ts Adds “LEAN GUI” nav label for quant-lab.
ui/src/i18n/locales/zh-Hant.ts Adds “LEAN GUI” nav label for quant-lab.
ui/src/components/lean/BacktestMetricsGrid.tsx Adds a metrics grid component to display key backtest statistics.
ui/src/components/ActivityBar.tsx Maps the new quant-lab page into the activity section model.
ui/src/components/ActivityBar.spec.ts Updates navigation hierarchy expectations to include LEAN GUI in Beta.
ui/src/components/activity-navigation.ts Adds the quant-lab rail item (icon + default tab).
ui/src/App.tsx Extends the Page union to include quant-lab.
src/workspaces/templates/chat/files/instruction.md Documents alice-quant + native lean CLI surfaces for workspaces.
src/workspaces/context-injector.ts Injects quant-lab skill into tool-bearing workspaces.
src/workspaces/context-injector.spec.ts Updates expectations for injected skills to include quant-lab.
src/workspaces/cli/bin/alice-quant.cmd Adds Windows launcher for alice-quant.
src/workspaces/cli/bin/alice-quant Adds POSIX launcher for alice-quant.
src/webui/routes/lean.ts Implements /api/lean/* backend routes for LEAN GUI feature set.
src/webui/routes/tests/lean.spec.ts Adds route-level tests for the LEAN WebUI API surface.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +61 to +78
// Create or link an experiment for this backtest
const exp = await leanApi.createExperiment({
strategyId: result.request.strategyId || result.request.strategyName,
hypothesis: `Research integrity evaluation for ${result.request.strategyName} (${result.request.symbol})`,
parameters: result.request.parameters || {},
inSamplePeriod: {
start: result.request.startDate,
end: result.request.endDate
},
instruments: [result.request.symbol]
})

if (exp?.experiment?.id) {
openOrFocus({
kind: 'quant-lab-integrity',
params: { experimentId: exp.experiment.id }
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants