Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
}
},
"files": {
"includes": ["**", "!node_modules", "!bun.lock", "!.*", "!coverage", "!dist", "!work"]
"includes": [
"**",
"!node_modules",
"!bun.lock",
"!.bun-cache",
"!.devos",
"!.ponytrail",
"!coverage",
"!dist",
"!work",
"!packages"
]
}
}
124 changes: 124 additions & 0 deletions scripts/demo-animation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#!/usr/bin/env bun
/**
* Demo script — runs the court animation end-to-end with fake bots.
* Usage: bun scripts/demo-animation.ts
*/
import { createCourtAnimator, printHorseRaceHeader, printRaceTrack } from "../src/court-animation";
import type { Manifest } from "../src/runtimes/ponytrail/manifest";
import type { RequirementCourtRound } from "../src/runtimes/ponytrail/requirement-court";

const manifest = {
manifestVersion: "0.1",
kind: "ai-work-runtime.ponytrail",
metadata: { name: "demo", description: "", owner: "human" },
runtime: { mode: "requirement_first", defaultLanguage: "en", workerAgents: [] },
models: [{ id: "m1", provider: "demo", name: "demo-model" }],
bots: [
{
id: "product_manager_bot",
displayName: "PM Bot",
role: "Product Manager",
panel: "requirement_court",
model: "m1",
instruction: "",
votes: true,
},
{
id: "engineer_bot",
displayName: "Engineer",
role: "Engineer",
panel: "requirement_court",
model: "m1",
instruction: "",
votes: true,
},
{
id: "testing_bot",
displayName: "Testing",
role: "QA",
panel: "requirement_court",
model: "m1",
instruction: "",
votes: true,
},
{
id: "senior_engineer_bot",
displayName: "Sr Engineer",
role: "Senior Engineer",
panel: "requirement_court",
model: "m1",
instruction: "",
votes: true,
},
],
deliberation: {
maxRounds: 1,
decisionRule: {
voterIds: ["product_manager_bot", "engineer_bot", "testing_bot", "senior_engineer_bot"],
voters: 4,
requiredApprovals: 3,
},
},
} as unknown as Manifest;

const sleep = (ms: number) => new Promise<void>((r) => setTimeout(r, ms));

const votes: Array<{ botId: string; displayName: string; vote: string }> = [
{ botId: "product_manager_bot", displayName: "PM Bot", vote: "approve" },
{ botId: "engineer_bot", displayName: "Engineer", vote: "amend" },
{ botId: "testing_bot", displayName: "Testing", vote: "approve" },
{ botId: "senior_engineer_bot", displayName: "Sr Engineer", vote: "approve" },
];

const animator = createCourtAnimator(manifest, {
minPonyMs: 1800, // show each pony for at least 1.8s
frameMs: 160, // gallop frame speed
});

await animator.onRoundStart(1, manifest.deliberation.decisionRule.voterIds);

const discussion: RequirementCourtRound["discussion"] = [];

for (const { botId, displayName, vote } of votes) {
await animator.onPonyStart(botId, displayName, 1);
// Simulate the bot "thinking" — just wait, the interval does the animation.
await sleep(2200);
const entry = {
botId,
displayName,
role: botId,
round: 1,
message: "deliberated",
visibleThinking: { focus: "", concern: "", recommendation: "" },
line: `${botId}: ${vote}`,
vote,
confidence: 0.9,
requiredChanges: vote === "amend" ? ["clarify scope"] : [],
} as RequirementCourtRound["discussion"][number];
discussion.push(entry);
await animator.onPonyComplete(entry);
}

const round: RequirementCourtRound = {
round: 1,
discussion,
votes: [],
verdict: {
approved: true,
approvals: 3,
amendments: 1,
rejections: 0,
missingVoters: [],
requiredChanges: [],
},
};

await animator.onRoundComplete(round);
animator.stop();

// Print full header first so you can see the starting lineup.
console.log("\n--- Replay: starting lineup ---\n");
printHorseRaceHeader(manifest);

console.log("\n--- Replay: race track ---\n");
printRaceTrack([round], manifest);
26 changes: 22 additions & 4 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { basename, isAbsolute, join, resolve } from "node:path";
import { confirm, intro, isCancel, outro, select, text } from "@clack/prompts";
import { Command } from "commander";
import pc from "picocolors";
import { type CourtAnimator, createCourtAnimator, printHorseRaceHeader } from "./court-animation";
import { installAgentSkill, parseSkillInstallAgents, type SkillInstallResult } from "./plugins";
import {
applySnapshotRevert,
Expand Down Expand Up @@ -643,6 +644,10 @@ async function runGoalFlow(requestParts: string[], input: RunGoalFlowInput): Pro
const request = requestParts.join(" ");
const preparedDiscussion = prepareGoalDiscussion(request, { manifest });

// Only animate in interactive TTY sessions, not when JSON output is requested.
const animator =
!input.jsonOutput && process.stdout.isTTY ? createCourtAnimator(manifest) : undefined;

if (preparedDiscussion.status === "needs_clarification") {
if (input.jsonOutput) {
console.log(JSON.stringify(preparedDiscussion, null, 2));
Expand Down Expand Up @@ -675,12 +680,14 @@ async function runGoalFlow(requestParts: string[], input: RunGoalFlowInput): Pro
return;
}

const result = await runRequirementCourt(
if (animator) printHorseRaceHeader(manifest);
const clarifiedResult = await runRequirementCourt(
clarifiedDiscussion.contract,
createRunRequirementCourtInput(manifest, input.ponyRunner),
createRunRequirementCourtInput(manifest, input.ponyRunner, animator),
);
animator?.stop();

printRequirementCourtResult(result, {
printRequirementCourtResult(clarifiedResult, {
discussionHeading: input.discussionHeading,
printVisibleThinking: input.printVisibleThinking,
});
Expand All @@ -692,10 +699,12 @@ async function runGoalFlow(requestParts: string[], input: RunGoalFlowInput): Pro
return;
}

if (animator) printHorseRaceHeader(manifest);
const result = await runRequirementCourt(
preparedDiscussion.contract,
createRunRequirementCourtInput(manifest, input.ponyRunner),
createRunRequirementCourtInput(manifest, input.ponyRunner, animator),
);
animator?.stop();

if (input.jsonOutput === "court") {
console.log(JSON.stringify(result, null, 2));
Expand All @@ -711,13 +720,22 @@ async function runGoalFlow(requestParts: string[], input: RunGoalFlowInput): Pro
function createRunRequirementCourtInput(
manifest: RunRequirementCourtInput["manifest"],
ponyRunner: RequirementPonyRunner | undefined,
animator?: CourtAnimator,
): RunRequirementCourtInput {
const input: RunRequirementCourtInput = { manifest };

if (ponyRunner) {
input.ponyRunner = ponyRunner;
}

if (animator) {
input.onRoundStart = (round, botIds) => animator.onRoundStart(round, botIds);
input.onRoundComplete = (round) => animator.onRoundComplete(round);
input.onPonyStart = (botId, displayName, round) =>
animator.onPonyStart(botId, displayName, round);
input.onPonyComplete = (entry) => animator.onPonyComplete(entry);
}

return input;
}

Expand Down
Loading
Loading