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.
70 lines (68 loc) • 2.06 kB
JavaScript
import {
parseArgs
} from "./bin-1gc4zavq.js";
import {
CliError,
EXIT
} from "./bin-t9ggwnv5.js";
import"./bin-wckvcay0.js";
// src/cli/commands/card.ts
import { existsSync, readFileSync, readdirSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
var CARD_MD = "card.md";
var CARD_JSON = "card.json";
function resolveDocsPublicDir() {
let dir = dirname(fileURLToPath(import.meta.url));
for (let i = 0;i < 6; i += 1) {
const candidate = join(dir, "docs", "public");
if (existsSync(join(candidate, CARD_MD)))
return candidate;
const parent = dirname(dir);
if (parent === dir)
break;
dir = parent;
}
throw new CliError({
code: "NOT_FOUND",
exit: EXIT.NOT_FOUND,
message: "the shipped agent card (docs/public/card.md) was not found next to the installed package",
hint: "reinstall kestrel.markets — `docs/public` is part of the published files allowlist"
});
}
function shippedTopics(dir) {
return readdirSync(dir).filter((f) => f.endsWith(".md")).map((f) => f.slice(0, -".md".length)).sort();
}
function cardCommand(argv, ctx) {
const { positionals } = parseArgs(argv);
const topic = positionals[0];
const dir = resolveDocsPublicDir();
if (topic === undefined) {
if (ctx.mode === "json") {
process.stdout.write(readFileSync(join(dir, CARD_JSON), "utf8"));
} else {
process.stdout.write(readFileSync(join(dir, CARD_MD), "utf8"));
}
return 0;
}
const topics = shippedTopics(dir);
if (!topics.includes(topic)) {
throw new CliError({
code: "USAGE",
exit: EXIT.USAGE,
message: `unknown card topic ${JSON.stringify(topic)}`,
hint: `valid topics: ${topics.join(", ")}`
});
}
const markdown = readFileSync(join(dir, `${topic}.md`), "utf8");
if (ctx.mode === "json") {
process.stdout.write(JSON.stringify({ schema: "kestrel.card.topic/v1", topic, markdown }) + `
`);
} else {
process.stdout.write(markdown);
}
return 0;
}
export {
cardCommand
};