UNPKG

kestrel.markets

Version:

A typed, token-efficient language + runtime for agentic trading: agents author bounded plans, the runtime fires them at the tick. CLI + typed library + MCP server.

61 lines (60 loc) 5.98 kB
/** * # session — the object that owns a run * * Charter: the one object that owns a run — `{ driver, clock, gate, bus, mode }` — with * modes **sim | paper | live** as one code path differing only in the gate adapter, so * grading is honest by construction. It also carries the **Wake router**, turning the * trigger algebra into attention: subscriptions carry attention budget, priority, and a * delivered View, never risk, and past budget wakes coalesce and downgrade (never * silently drop — the squelch is visible in the kernel). A Pod definition is a **class**; * a run of it is an **instance** = (definition version × mode × run id): sim and paper * instances are unbounded, but **the live instance is a singleton per pod lineage, * platform-enforced**. Promotion is a document revision of the live pod, never a flag * flip. This is the single thing the HTTP/SSE, CLI, and MCP surfaces sit on. * * ## Shipped in this milestone — the sim driver (RUNTIME §7) * {@link ./sim.ts} implements the `sim` code path end to end: read a recorded/synthetic bus, * drive canonical state + the {@link ../engine PlanEngine} trigger sweep, route orders through * the Gate into a {@link ../fill SimFillEngine}, reassess fills on BOOK events, cash-settle at * intrinsic, and return a graded {@link EpisodeReport} with a determinism hash over the emitted * event stream. {@link ./cli.ts} is the loud, fail-closed CLI over it. The Wake router, the * paper/live gates, and the multi-mode surfaces land in later milestones. */ export { runSimSession, writeReport, SessionCore, requireMeta, resolveSpecs, busSha256Of, stampGradedMeta, assembleGradedBus, fillModelStampOf, instanceIdentityOf, fidelityOf, canonicalPlansTextOf, closingParitySpot, /** kestrel-wcnd: the machine-readable reason code an unknowable-τ de-arm carries. */ FAIR_TAU_UNKNOWN_CODE, } from "./sim.js"; // Clock helpers — the per-event time-to-expiry (τ) provider and ET wall-clock math. // Surfaced here (and thus on the `./engine` `session` namespace) so a Worker-bundled // consumer can obtain the default τ provider by a static import instead of a deep // `dist/session/clock.js` path (which the package `exports` map does not surface). // // kestrel-wcnd: `expiryTauYears` REPLACES the removed `dynamicTauYears`. The rename is // deliberate and breaking: the old name returned time-to-SESSION-CLOSE and could not // see the contract's expiry at all, so a caller that kept it would keep mispricing every // multi-day contract by ~16×. Callers pass the same `meta.session_date` and additionally // thread the per-book `expiry` at the call site (the provider's 2nd argument). export { expiryTauYears, etMinuteOfDay, etWallClockMs, } from "./clock.js"; export { runDaySession, computeWakes, parseWakeTimes, parseClockET, reanchorFrontier, authorCutoffTs, REGULAR_OPEN, AUTHOR_CUTOFF_LEAD_MIN, machineSummary, projectAuthorFrame, scanDateLeak, assertDateBlind, DATE_LEAK_PATTERNS, } from "./day.js"; export { fixedPlanAgent, recordedAgent, wakeKeyOf, assertHandlerResponseTimeless, OPEN_ORDINAL, OPEN_WAKE_KEY, BACKTEST_CONFIG, } from "./agent.js"; // The BYOK live agent — provider-free: only the pure `liveAgent` adapter + the prompt profile / // fail-closed turn parser are re-exported here, so importing `session/index.ts` never pulls a // provider SDK (ADR-0013). The wire-touching AI-SDK `LlmClient` lives at `./harness/ai-sdk-client.ts` // and is imported directly (or via `./harness/index.ts`) by a live-run script — never re-exported here. export { liveAgent, LIVE_AGENT_ADAPTER, LIVE_AGENT_ADAPTER_VERSION, DEFAULT_CACHE_POLICY, } from "./harness/live-agent.js"; // The file-handshake adapter — the versioned seam every external CLI harness drives through // (kestrel-m9i.7 stage-0). Provider-free (it imports only `node:fs` + the pure prompt parser), so // re-exporting it from this deterministic-core barrel never pulls a provider SDK (ADR-0013). export { fileHandshakeAgent, FILE_HANDSHAKE_ADAPTER, FILE_HANDSHAKE_ADAPTER_VERSION, STAND_DOWN_SENTINEL, DEFAULT_TIMEOUT_MS, ordLabelOf, serializeFrameEnvelope, renderFrameText, timeoutTurn, parseHandshakeTurn, stampHarnessIdentity, } from "./harness/file-handshake.js"; export { BASELINE_SYSTEM_PROMPT, BASELINE_PROMPT_PROFILE, AUTHORING_SYSTEM_PROMPT, AUTHORING_PROMPT_PROFILE, AUTHORING_EXAMPLE_DOCUMENTS, AUTHORING_EXAMPLE_DOCUMENT_LIST, VIEWSHOP_SYSTEM_PROMPT, VIEWSHOP_PROMPT_PROFILE, MANAGE_SYSTEM_PROMPT, MANAGE_PROMPT_PROFILE, DEFAULT_PROMPT_PROFILE, systemPromptForProfile, CREDENTIAL_ENV_VARS, parseTurn, parseAuthoringReply, describeAction, scrubSecrets, renderBriefingPrompt, renderRepairPrompt, renderReprompt, renderWakePrompt, REPROMPT_WITHHELD, } from "./harness/prompt.js"; export { runSimulateSession, projectWakeFrame, sizingHeadroomOf, vehicleHealthOf, vehicleBookFromSpot, DEFAULT_VIEW_REQUEST_CAP, DEFAULT_AUTHORING_TOKEN_BUDGET, } from "./simulate.js"; // The PAPER session driver (kestrel-7o2.12) — the first production caller of `makeGate("paper", …)`. // Re-exported here as the sim drivers are; the module's static graph carries NO socket (every // `@stoqey/ib`-bound module is behind a lazy `import()` inside the venue composition), so importing // this barrel never pulls the IB client. export { runPaperSession, openPaperSession, ibkrPaperVenue, assertBoundedLimits, PaperSessionRefused, PaperBus, DEFAULT_PUMP_MS, } from "./paper.js"; export { canonicalizeConfig, deriveConfigId, cellCanonicalConfig, cellConfigId, envelopeOf, envelopeForConfig, declaresEnvelope, fillSeedOf, sampledQualificationOf, } from "./config.js"; export { openSession, resumeSession, } from "./controller.js"; export { SimRunId, CellKey, cellOf, InstanceRunId, SequenceCellKey } from "./run-identity.js"; export { runInstance, } from "./instance.js"; export { emptyCarry, assertCarry, carryFrom, } from "./carry.js"; export { buildGrid, leaderboard, buildInstanceBlotter, buyAndHoldBaseline, } from "./grid.js";