export type DemoLanguage = "python" | "javascript" | "typescript" | "bash"; export type DemoVariant = "standard" | "eof" | "verbose"; export type DemoScenarioKey = | "python" | "python-eof" | "python-verbose" | "javascript" | "javascript-eof" | "javascript-verbose" | "typescript" | "typescript-eof" | "typescript-verbose" | "bash" | "bash-eof" | "bash-verbose"; export interface DemoSample { key: DemoScenarioKey; language: DemoLanguage; variant: DemoVariant; label: string; variantLabel: string; model: string; prompt: string; toolCallId: string; bashCommand: string; } function joinLines(lines: readonly string[]): string { return lines.join("\n"); } export const STANDARD_PYTHON_SAMPLE_COMMAND = joinLines([ "python3 <<'PY'", "#!/usr/bin/env python3", "", "def main() -> None:", ' print("hello from py")', "", 'if __name__ == "__main__":', " main()", "PY", ]); export const EOF_PYTHON_SAMPLE_COMMAND = joinLines([ "python3 <<'EOF'", "#!/usr/bin/env python3", "", "def main() -> None:", ' print("hello from py", 42)', "", 'if __name__ == "__main__":', " main()", "EOF", ]); export const VERBOSE_PYTHON_SAMPLE_COMMAND = joinLines([ "python3 <<'PY'", "#!/usr/bin/env python3", "# -*- coding: utf-8 -*-", "# Single-line comment", "", '"""', "Module docstring — should look different from regular strings.", "Doctest inside:", " >>> 1 + 1", " 2", '"""', "from __future__ import annotations", "", "# ── Imports ───────────────────────────────────────────────────────────────", "import asyncio", "import keyword", "import re", "from typing import Final, Generic, Literal, Optional, TypeVar, Union, overload", "", "# ── Runtime helpers ───────────────────────────────────────────────────────", "x = 3.14159", 'data = b"abcdefgh"', 'command = {"action": "quit"}', 'items = {"one": 1, "two": 2}', "matrix = [[1, 2], [3, 4]]", 'T = TypeVar("T")', "type Vector = list[float]", "", "# ── Numbers ───────────────────────────────────────────────────────────────", "dec = 42", "hex_ = 0xDEAD_BEEF", "oct_ = 0o755", "bin_ = 0b0010_0001", "big = 1_000_000", "flt = 3.14", "sci = 6.626e-34", "leading = .5", "trailing = 5.", "cmplx = 1.5 + 2j", "", "# ── Strings ───────────────────────────────────────────────────────────────", 'plain = "double"', "single = 'single'", 'raw = r"raw \\n \\t no-escape"', 'byt = b"\\xff\\x00"', 'uni = u"unicode prefix"', 'rb_ = rb"\\xff literal"', 'escapes = "newline\\n tab\\t hex\\x41 unicode\\u0041 null\\0 bell\\a"', 'triple_d = """triple', 'double"""', "triple_s = '''triple", "single'''", 'raw_tri = r"""raw \\t triple"""', 'f1 = f"simple {x}"', 'f2 = f"expr {1 + 1}"', 'f3 = f"repr {x!r} str {x!s} ascii {x!a}"', 'f4 = f"spec {x:.2f} {x:>10}"', 'f5 = f"debug {x = }"', "f6 = f\"nested {f'inner {x}'}\"", 'f7 = rf"raw-f \\n literal {x}"', 'impl = "one" " two" r" \\three" f" {x}"', "", "# ── Operators and collections ─────────────────────────────────────────────", "arith = 1 + 2 - 3 * 4 / 5 // 6 % 7 ** 2", "bitwise = 0xFF & 0x0F | 0xF0 ^ 0xAA << 2 >> 1", "logical = True and False or not False", "compare = 1 < 2 <= 3 == 3 != 4 >= 4 > 0", "ident = x is None, x is not None, x in [x], x not in []", "walrus = (n := 10)", "lst = [value * value for value in range(10) if value % 2 == 0]", "dct = {k: v for k, v in items.items()}", "st = {value % 7 for value in range(20)}", "gen = (value for value in range(5))", "nest = [cell for row in matrix for cell in row]", "", "# ── Functions and classes ─────────────────────────────────────────────────", "def simple(a, b=1, *args, kw=0, kw2=None, **kwargs):", " return a + b + kw + len(args) + len(kwargs)", "", "def posonly(a, b, /, c, d):", " return a + b + c + d", "", 'def with_annotations(x: int, y: str = "hi") -> bool:', " return bool(x) and bool(y)", "", "def generator():", " yield 1", " yield from range(2, 4)", "", "def decorator(fn):", " return fn", "", "def deco_factory(arg, **kwargs):", " def apply(fn):", " return fn", " return apply", "", "@decorator", '@deco_factory("arg")', '@deco_factory("named", key="value")', "def decorated() -> str:", ' return "decorated"', "", "class Base:", ' """Class docstring."""', " class_var: int = 0", ' __slots__ = ("x",)', "", " def __init__(self) -> None:", " self.x = 0", "", " def __repr__(self) -> str:", ' return f"{type(self).__name__}()"', "", " @classmethod", ' def create(cls) -> "Base":', " return cls()", "", " @staticmethod", " def util(value: int) -> int:", " return value * 2", "", " @property", " def value(self) -> int:", " return self.x", "", " @value.setter", " def value(self, v: int) -> None:", " self.x = v", "", "class Child(Base, metaclass=type):", " pass", "", "class Stack(Generic[T]):", " def __init__(self, values: Optional[list[T]] = None) -> None:", " self.values = values or []", "", " def push(self, value: T) -> None:", " self.values.append(value)", "", " def first(self) -> T:", " return self.values[0]", "", "@overload", "def first_item(value: list[int]) -> int: ...", "@overload", "def first_item(value: list[str]) -> str: ...", "def first_item(value):", " return value[0]", "", "x_opt: Optional[int] = None", "y_union: Union[int, str] = 0", "z_pipe: int | str | None = 0", "w_final: Final[int] = 42", 'l_lit: Literal["a", "b", 1] = "a"', "", "# ── Async, context, match, regex ──────────────────────────────────────────", "class AsyncContext:", ' async def __aenter__(self) -> "AsyncContext":', " return self", "", " async def __aexit__(self, exc_type, exc, tb) -> None:", " return None", "", "async def coro() -> None:", " await asyncio.sleep(0)", "", "async def agen():", " for value in range(3):", " yield value", "", "async def use_async() -> list[int]:", " async with AsyncContext() as ctx:", " await coro()", " return [value async for value in agen() if value > 0]", "", "def showcase_runtime() -> tuple[bool, str]:", " match command:", ' case {"action": "quit"}:', ' mode = "quit"', ' case {"action": str(action), "val": int(value)} if value > 0:', " mode = action", " case [first, *rest]:", ' mode = f"list:{first}:{len(rest)}"', " case _:", ' mode = "other"', ' pat = re.compile(r"""', " ^(?P[a-z_]+) # word", " (?P\\d+)? # optional digits", " $", ' """.strip(), re.VERBOSE)', ' return pat.match("token42") is not None, mode', "", "def main() -> None:", " stack = Stack[int]([1, 2, 3])", " ok, mode = showcase_runtime()", " total = sum(generator()) + dec + len(keyword.kwlist) + stack.first()", ' print("hello from verbose py", total, ok, mode, first_item(["x", "y"]))', "", 'if __name__ == "__main__":', " main()", "PY", ]); export const STANDARD_JAVASCRIPT_SAMPLE_COMMAND = joinLines([ "node <<'JS'", "const value = 42;", 'console.log("hello from js", value);', "JS", ]); export const EOF_JAVASCRIPT_SAMPLE_COMMAND = joinLines([ "node <<'EOF'", "const value = 42;", 'console.log("hello from js", value);', "EOF", ]); export const VERBOSE_JAVASCRIPT_SAMPLE_COMMAND = joinLines([ "node <<'JS'", "#!/usr/bin/env node", "'use strict';", "// Single-line comment", "", "/* Multi-line comment with punctuation: [] {} () => */", "const decimal = 42;", "const hex = 0xfeed_beef;", "const binary = 0b1010_0101;", "const octal = 0o755;", "const big = 9_007_199_254_740_991n;", "const float = 3.14159;", "const sci = 6.022e23;", "const truthy = true && !false;", "const nothing = null ?? 'fallback';", "", 'const plain = "double";', "const single = 'single';", 'const escapes = "line\\n tab\\t unicode \\u03c0";', "const regex = /^(?[a-z]+)-(\\d+)$/giu;", "const template = `sum=${decimal + float}`;", "const tagged = String.raw`raw\\n${decimal}`;", "", "const numbers = [1, 2, 3, 4, 5].map((value) => value ** 2);", "const nested = [[1, 2], [3, 4]].flatMap((row) => row.map((cell) => cell * 2));", "const object = { plain, single, nested, ['dynamic-key']: template };", "const { plain: alias, ...rest } = object;", "const optional = rest?.nested?.[1] ?? 0;", "", "function add(a = 1, b = 2, ...restValues) {", " return a + b + restValues.reduce((sum, value) => sum + value, 0);", "}", "", "function* counter(limit = 3) {", " for (let index = 0; index < limit; index += 1) {", " yield index;", " }", "}", "", "async function* asyncCounter(limit = 2) {", " for (const value of counter(limit)) {", " yield Promise.resolve(value);", " }", "}", "", "class Base {", " static kind = 'base';", " #value = 0;", "", " constructor(name = 'demo') {", " this.name = name;", " }", "", " get value() {", " return this.#value;", " }", "", " set value(next) {", " this.#value = next;", " }", "", " method(extra = 0) {", " return `${this.name}:${this.#value + extra}`;", " }", "}", "", "class Child extends Base {", " static from(entries) {", " return new Child(entries.join('-'));", " }", "}", "", "const instance = Child.from(['verbose', 'js']);", "instance.value = add(1, 2, 3, 4);", "", "let mode = 'init';", "switch (instance.name) {", " case 'verbose-js':", " mode = 'switch-hit';", " break;", " default:", " mode = 'switch-miss';", "}", "", "try {", " if (!regex.test('token-42')) {", " throw new Error('regex mismatch');", " }", "} catch (error) {", " mode = error instanceof Error ? error.message : 'unknown';", "} finally {", " mode = `${mode}:done`;", "}", "", "(async () => {", " const asyncValues = [];", " for await (const value of asyncCounter()) {", " asyncValues.push(await value);", " }", " const summary = [alias, optional, truthy, numbers.at(-1), nested.length, big > 0n].join('|');", " console.log('hello from verbose js', instance.method(decimal), summary, mode, asyncValues.join(','), tagged);", "})();", "JS", ]); export const STANDARD_TYPESCRIPT_SAMPLE_COMMAND = joinLines([ "npx tsx <<'TS'", "type Answer = {", " value: number;", "};", "", "const answer: Answer = { value: 42 };", 'console.log("hello from ts", answer.value);', "TS", ]); export const EOF_TYPESCRIPT_SAMPLE_COMMAND = joinLines([ "npx tsx <<'EOF'", "type Answer = {", " value: number;", "};", "", "const answer: Answer = { value: 42 };", 'console.log("hello from ts", answer.value);', "EOF", ]); export const VERBOSE_TYPESCRIPT_SAMPLE_COMMAND = joinLines([ "npx tsx <<'TS'", "#!/usr/bin/env -S npx tsx", "// Single-line comment", "", "type Identifier = `item-${number}`;", "type Status = 'idle' | 'running' | 'done';", "type Result = { ok: true; value: T } | { ok: false; error: Error };", "type HttpMethod = 'GET' | 'POST';", "", "interface Entry {", " id: Identifier;", " label: string;", " value: TValue;", " status: Status;", "}", "", "interface Runner {", " run(task: string): Promise>;", "}", "", "type WithTimestamp = T & { createdAt: Date };", "type EventName = `on${Capitalize}`;", "", "const decimal = 42;", "const hex = 0xfeed_beef;", "const binary = 0b1010_0101;", "const bigintValue = 9_007_199_254_740_991n;", "const tuple = ['alpha', 2, true] as const;", "const routes = { home: '/', docs: '/docs' } as const satisfies Record;", "", "function identity(value: T): T {", " return value;", "}", "", "function first(values: readonly T[]): T | undefined {", " return values[0];", "}", "", "function formatValue(value: number): string;", "function formatValue(value: string): string;", "function formatValue(value: number | string): string {", " return typeof value === 'number' ? value.toFixed(2) : value.toUpperCase();", "}", "", "class TaskRunner implements Runner {", " readonly #prefix: string;", "", " constructor(prefix: string) {", " this.#prefix = prefix;", " }", "", " async run(task: string): Promise> {", " return { ok: true, value: `${this.#prefix}:${task}` };", " }", "}", "", "async function collect(values: AsyncIterable): Promise {", " const output: T[] = [];", " for await (const value of values) {", " output.push(value);", " }", " return output;", "}", "", "async function* streamEntries(values: Entry[]) {", " for (const entry of values) {", " yield { ...entry, createdAt: new Date('2024-01-01T00:00:00Z') } satisfies WithTimestamp>;", " }", "}", "", "const entries: Entry[] = [", " { id: 'item-1', label: 'alpha', value: 1, status: 'idle' },", " { id: 'item-2', label: 'beta', value: 2, status: 'running' },", " { id: 'item-3', label: 'gamma', value: 3, status: 'done' },", "];", "", "function summarize(entry: Entry): string {", " switch (entry.status) {", " case 'idle':", " return `${entry.label}:waiting`;", " case 'running':", " return `${entry.label}:active`;", " case 'done':", " return `${entry.label}:complete`;", " default:", " return entry satisfies never;", " }", "}", "", "async function main(): Promise {", " const runner = new TaskRunner('verbose-ts');", " const result = await runner.run('compile');", " const streamed = await collect(streamEntries(entries));", " const eventName: EventName<'save'> = 'onSave';", " const total = entries.reduce((sum, entry) => sum + entry.value, 0);", " const formatted = [formatValue(decimal), formatValue('ok'), identity(routes.docs)].join('|');", " const firstEntry = first(entries)?.label ?? 'none';", " const summary = streamed.map((entry) => summarize(entry)).join(',');", " const finalValue = result.ok ? result.value : result.error.message;", " console.log('hello from verbose ts', finalValue, total + hex + binary, bigintValue > 0n, tuple[0], firstEntry, eventName, formatted, summary);", "}", "", "void main();", "TS", ]); export const STANDARD_BASH_SAMPLE_COMMAND = joinLines([ "bash <<'SH'", "set -euo pipefail", 'echo "hello from sh"', "SH", ]); export const EOF_BASH_SAMPLE_COMMAND = joinLines([ "bash <<'EOF'", "set -euo pipefail", 'echo "hello from sh"', "EOF", ]); export const VERBOSE_BASH_SAMPLE_COMMAND = joinLines([ "bash <<'SH'", "#!/usr/bin/env bash", "# Single-line comment", "set -euo pipefail", "shopt -s extglob", "", 'readonly script_name="${0##*/}"', 'declare -a indexed=("alpha" "beta" "gamma")', 'declare -A palette=([primary]="blue" [accent]="cyan")', 'name=" pi demo "', 'trimmed="${name#"${name%%[![:space:]]*}"}"', 'trimmed="${trimmed%"${trimmed##*[![:space:]]}"}"', 'upper="${trimmed^^}"', 'slug="${upper// /-}"', "arith=$((16#2A + 2))", 'printf -v joined "%s:" "${indexed[@]}"', 'joined="${joined%:}"', "", 'mapfile -t records < <(printf "%s\\n" "one:1" "two:2" "three:3")', 'first_record="${records[0]}"', 'if [[ "$first_record" =~ ^([a-z]+):([0-9]+)$ ]]; then', ' key="${BASH_REMATCH[1]}"', ' value="${BASH_REMATCH[2]}"', "else", ' key="missing"', ' value="0"', "fi", "", 'case "${palette[primary]}" in', ' blue|cyan) mode="cool" ;;', ' *) mode="other" ;;', "esac", "", "render_block() {", ' local title="$1"', " cat < "$tmpfile"', 'summary="${heredoc_lines[0]}:${key}:${value}:${arith}:${mode}:${sum}"', 'printf "hello from verbose sh %s %s %s\\n" "$summary" "${palette[accent]}" "$(<"$tmpfile")"', "SH", ]); export const DEMO_SAMPLE_VARIANTS = { python: { standard: { key: "python", language: "python", variant: "standard", label: "Python", variantLabel: "Explicit marker", model: "canonical-heredoc-compare", prompt: "Use bash to run python from a heredoc with python3. Use PY as the heredoc delimiter exactly. Keep the transcript inline and normal.", toolCallId: "call_inline_format_deterministic_python_bash", bashCommand: STANDARD_PYTHON_SAMPLE_COMMAND, }, eof: { key: "python-eof", language: "python", variant: "eof", label: "Python", variantLabel: "EOF basic", model: "python-heredoc-eof-compare", prompt: "Use bash to run python from a heredoc with python3. Use EOF as the heredoc delimiter exactly. Keep the transcript inline and normal.", toolCallId: "call_inline_format_deterministic_python_eof_bash", bashCommand: EOF_PYTHON_SAMPLE_COMMAND, }, verbose: { key: "python-verbose", language: "python", variant: "verbose", label: "Python", variantLabel: "Verbose", model: "python-heredoc-verbose-compare", prompt: "Use bash to run a verbose python syntax showcase from a heredoc with python3. Keep the transcript inline and normal.", toolCallId: "call_inline_format_deterministic_python_verbose_bash", bashCommand: VERBOSE_PYTHON_SAMPLE_COMMAND, }, }, javascript: { standard: { key: "javascript", language: "javascript", variant: "standard", label: "JavaScript", variantLabel: "Explicit marker", model: "javascript-heredoc-compare", prompt: "Use bash to run javascript from a heredoc with node. Use JS as the heredoc delimiter exactly. Keep the transcript inline and normal.", toolCallId: "call_inline_format_deterministic_javascript_bash", bashCommand: STANDARD_JAVASCRIPT_SAMPLE_COMMAND, }, eof: { key: "javascript-eof", language: "javascript", variant: "eof", label: "JavaScript", variantLabel: "EOF basic", model: "javascript-heredoc-eof-compare", prompt: "Use bash to run javascript from a heredoc with node. Use EOF as the heredoc delimiter exactly. Keep the transcript inline and normal.", toolCallId: "call_inline_format_deterministic_javascript_eof_bash", bashCommand: EOF_JAVASCRIPT_SAMPLE_COMMAND, }, verbose: { key: "javascript-verbose", language: "javascript", variant: "verbose", label: "JavaScript", variantLabel: "Verbose", model: "javascript-heredoc-verbose-compare", prompt: "Use bash to run a verbose javascript syntax showcase from a heredoc with node. Keep the transcript inline and normal.", toolCallId: "call_inline_format_deterministic_javascript_verbose_bash", bashCommand: VERBOSE_JAVASCRIPT_SAMPLE_COMMAND, }, }, typescript: { standard: { key: "typescript", language: "typescript", variant: "standard", label: "TypeScript", variantLabel: "Explicit marker", model: "typescript-heredoc-compare", prompt: "Use bash to run typescript from a heredoc with npx tsx. Use TS as the heredoc delimiter exactly. Keep the transcript inline and normal.", toolCallId: "call_inline_format_deterministic_typescript_bash", bashCommand: STANDARD_TYPESCRIPT_SAMPLE_COMMAND, }, eof: { key: "typescript-eof", language: "typescript", variant: "eof", label: "TypeScript", variantLabel: "EOF basic", model: "typescript-heredoc-eof-compare", prompt: "Use bash to run typescript from a heredoc with npx tsx. Use EOF as the heredoc delimiter exactly. Keep the transcript inline and normal.", toolCallId: "call_inline_format_deterministic_typescript_eof_bash", bashCommand: EOF_TYPESCRIPT_SAMPLE_COMMAND, }, verbose: { key: "typescript-verbose", language: "typescript", variant: "verbose", label: "TypeScript", variantLabel: "Verbose", model: "typescript-heredoc-verbose-compare", prompt: "Use bash to run a verbose typescript syntax showcase from a heredoc with npx tsx. Keep the transcript inline and normal.", toolCallId: "call_inline_format_deterministic_typescript_verbose_bash", bashCommand: VERBOSE_TYPESCRIPT_SAMPLE_COMMAND, }, }, bash: { standard: { key: "bash", language: "bash", variant: "standard", label: "Bash", variantLabel: "Explicit marker", model: "bash-heredoc-compare", prompt: "Use bash to run shell from a heredoc with bash. Use SH as the heredoc delimiter exactly. Keep the transcript inline and normal.", toolCallId: "call_inline_format_deterministic_bash_bash", bashCommand: STANDARD_BASH_SAMPLE_COMMAND, }, eof: { key: "bash-eof", language: "bash", variant: "eof", label: "Bash", variantLabel: "EOF basic", model: "bash-heredoc-eof-compare", prompt: "Use bash to run shell from a heredoc with bash. Use EOF as the heredoc delimiter exactly. Keep the transcript inline and normal.", toolCallId: "call_inline_format_deterministic_bash_eof_bash", bashCommand: EOF_BASH_SAMPLE_COMMAND, }, verbose: { key: "bash-verbose", language: "bash", variant: "verbose", label: "Bash", variantLabel: "Verbose", model: "bash-heredoc-verbose-compare", prompt: "Use bash to run a verbose bash syntax showcase from a heredoc with bash. Keep the transcript inline and normal.", toolCallId: "call_inline_format_deterministic_bash_verbose_bash", bashCommand: VERBOSE_BASH_SAMPLE_COMMAND, }, }, } as const satisfies Record>; export const DEMO_LANGUAGE_ORDER = [ "python", "javascript", "typescript", "bash", ] as const satisfies readonly DemoLanguage[]; export const DEMO_VARIANT_ORDER = [ "standard", "eof", "verbose", ] as const satisfies readonly DemoVariant[]; export const INLINE_DETERMINISTIC_SCENARIOS = DEMO_LANGUAGE_ORDER.flatMap( (language) => DEMO_VARIANT_ORDER.map( (variant) => DEMO_SAMPLE_VARIANTS[language][variant], ), ); export const STANDARD_SAMPLE_COMMANDS = { python: STANDARD_PYTHON_SAMPLE_COMMAND, javascript: STANDARD_JAVASCRIPT_SAMPLE_COMMAND, typescript: STANDARD_TYPESCRIPT_SAMPLE_COMMAND, bash: STANDARD_BASH_SAMPLE_COMMAND, } as const; export const EOF_SAMPLE_COMMANDS = { python: EOF_PYTHON_SAMPLE_COMMAND, javascript: EOF_JAVASCRIPT_SAMPLE_COMMAND, typescript: EOF_TYPESCRIPT_SAMPLE_COMMAND, bash: EOF_BASH_SAMPLE_COMMAND, } as const;