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.
107 lines (105 loc) • 3.9 kB
JavaScript
import {
HostedFunnel,
loadStrategy,
nearMissSlugs,
parseSimSelector,
resolveCopyToken,
resolveScenarioSlug,
resolveSimBase,
runHostedProof,
slugifyTitle
} from "./bin-69rn2kv7.js";
import"./bin-awvz75fn.js";
import {
defaultHostedStorePath
} from "./bin-m9a64j9t.js";
import"./bin-qewrvqtv.js";
import"./bin-x2cbtyjz.js";
import {
parseArgs
} from "./bin-1gc4zavq.js";
import {
CliError,
EXIT
} from "./bin-t9ggwnv5.js";
import"./bin-29be75ss.js";
import"./bin-8pchjxn2.js";
import"./bin-2ywrx58g.js";
import"./bin-wckvcay0.js";
// src/cli/commands/prove.ts
var DEFAULT_PROVE_SLUG = "mean-reversion-range-fade";
var SAMPLER_STARTER_DOC = `PLAN starter budget 1R ttl +24h
WHEN spot > 0
DO buy 1 shares @ spot`;
var SAMPLER_STARTER_LABEL = "sampler starter (bundled example — supply --plans <file> to author your own)";
var SWAP_IN_CLI = "npx kestrel.markets prove --plans <your-plan.kestrel>";
function selectDefaultScenario(entries) {
const pinned = resolveScenarioSlug(DEFAULT_PROVE_SLUG, entries);
if (pinned !== null && pinned.entry.free)
return pinned;
const firstFree = entries.find((e) => e.free);
if (firstFree === undefined)
throw new CliError({
code: "NOT_FOUND",
exit: EXIT.NOT_FOUND,
message: "no free scenario is available for `prove` — the hosted catalog offered none",
hint: "run `kestrel sim` to see the catalog, or name a scenario: `kestrel prove <slug>`"
});
const slug = slugifyTitle(firstFree.title);
return { entry: firstFree, canonicalSlug: slug, requestedSlug: slug, viaAlias: false };
}
async function proveCommand(argv, ctx, globals, deps = {}) {
const { positionals, flags, bools } = parseArgs(argv, new Set(["no-residency"]), new Set(["plans", "copy-token"]));
const env = deps.env ?? process.env;
const base = resolveSimBase(globals, env);
const client = new HostedFunnel({ baseUrl: base, ...deps.fetch !== undefined ? { fetch: deps.fetch } : {} });
const { entries } = await client.catalog();
let resolved;
if (positionals.length === 0) {
const select = deps.selectDefault ?? selectDefaultScenario;
const picked = select(entries);
if (picked === undefined)
throw new CliError({
code: "NOT_FOUND",
exit: EXIT.NOT_FOUND,
message: "`prove` could not select a default scenario — the front door refuses to fall through to a menu",
hint: "name a scenario: `kestrel prove <slug>`, or run `kestrel sim` for the catalog"
});
resolved = picked;
} else {
const { scenarioSlug } = parseSimSelector(positionals);
const match = resolveScenarioSlug(scenarioSlug, entries);
if (match === null) {
const near = nearMissSlugs(scenarioSlug, entries);
throw new CliError({
code: "NOT_FOUND",
exit: EXIT.NOT_FOUND,
message: `unknown scenario slug ${JSON.stringify(scenarioSlug)}`,
hint: near.length > 0 ? `did you mean: ${near.join(", ")}? — run \`kestrel sim\` for the full menu` : "run `kestrel sim` for the menu"
});
}
resolved = match;
}
const plansPath = flags.get("plans");
const usingBundledStarter = plansPath === undefined;
const strategy = loadStrategy(plansPath, { source: SAMPLER_STARTER_DOC, label: SAMPLER_STARTER_LABEL });
const copyToken = resolveCopyToken(flags, env);
return runHostedProof({
client,
resolved,
strategy,
ctx,
hostedStorePath: deps.hostedStorePath ?? defaultHostedStorePath(env),
emitResidency: !bools.has("no-residency"),
authoredPlan: !usingBundledStarter,
...usingBundledStarter ? { demoLesson: { planLabel: SAMPLER_STARTER_LABEL, planSource: strategy.source, swapInCli: SWAP_IN_CLI } } : {},
...copyToken !== undefined ? { copyToken } : {}
});
}
export {
selectDefaultScenario,
proveCommand,
SAMPLER_STARTER_LABEL,
SAMPLER_STARTER_DOC,
DEFAULT_PROVE_SLUG
};