Web UI (tinyclaw web): - Flask + SSE real-time progress streaming - Queue view: add/delete tasks, status colours, error display - Live log panel with coloured output - History tab with unified diffs (Rosé Pine theme) - Model picker dropdown - Auto-refresh every 5s History (history.py): - JSONL-based, records before/after content + unified diff - Wired into driver for EDIT and CREATE actions - Failed tasks also recorded QA benchmark (tinyclaw qa <models...>): - 5 fixed tasks: divide/greet/is_even/repeat/safe_get - Scores syntax validity + instruction following - Comparison table: pass%, syntax%, latency, cost QA results (3 models): - gemma-3-12b-it: 80% pass, 100% syntax, ~944ms ← winner - gemma-3-4b-it: 60% pass, 100% syntax, ~917ms - qwen2.5-coder-7b: 0% pass, 0% syntax (max_tokens issue — hits 512 limit mid-function)
194 lines
8.1 KiB
Python
194 lines
8.1 KiB
Python
"""TinyClaw CLI entry point."""
|
|
|
|
import argparse
|
|
import os
|
|
import sys
|
|
|
|
from tinyclaw.driver import RunConfig, run, status
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(
|
|
description="TinyClaw: orchestrate tiny models for real project work",
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
epilog="""
|
|
Examples:
|
|
tinyclaw run --queue QUEUE.md --model qwen/qwen3.5-1.5b
|
|
tinyclaw run --dry-run
|
|
tinyclaw status
|
|
tinyclaw plan "add input validation to all API endpoints"
|
|
""",
|
|
)
|
|
|
|
sub = parser.add_subparsers(dest="command", metavar="command")
|
|
|
|
# ── run ──────────────────────────────────────────────────────────
|
|
run_p = sub.add_parser("run", help="Process task queue")
|
|
run_p.add_argument("--queue", default="QUEUE.md", help="Path to queue file (default: QUEUE.md)")
|
|
run_p.add_argument(
|
|
"--model",
|
|
default=os.environ.get("TINYCLAW_MODEL", "qwen/qwen3.5-1.5b"),
|
|
help="Model ID on OpenRouter or local endpoint (default: qwen/qwen3.5-1.5b)",
|
|
)
|
|
run_p.add_argument("--api-base", default=None, help="API base URL (default: OpenRouter)")
|
|
run_p.add_argument("--api-key", default=None, help="API key (default: OPENROUTER_API_KEY env)")
|
|
run_p.add_argument("--max-tokens", type=int, default=1024, help="Max tokens per completion")
|
|
run_p.add_argument("--temperature", type=float, default=0.1, help="Sampling temperature")
|
|
run_p.add_argument("--no-commit", action="store_true", help="Don't auto-commit after each task")
|
|
run_p.add_argument("--dry-run", action="store_true", help="Parse queue and show tasks without running")
|
|
run_p.add_argument("-v", "--verbose", action="store_true", help="Verbose output")
|
|
|
|
# ── status ───────────────────────────────────────────────────────
|
|
status_p = sub.add_parser("status", help="Show queue status")
|
|
status_p.add_argument("--queue", default="QUEUE.md", help="Path to queue file")
|
|
|
|
# ── web ──────────────────────────────────────────────────────────
|
|
web_p = sub.add_parser("web", help="Launch web UI")
|
|
web_p.add_argument("--queue", default="QUEUE.md", help="Queue file")
|
|
web_p.add_argument("--history", default="HISTORY.jsonl",help="History file")
|
|
web_p.add_argument("--host", default="127.0.0.1")
|
|
web_p.add_argument("--port", default=7842, type=int)
|
|
|
|
# ── qa ───────────────────────────────────────────────────────────
|
|
qa_p = sub.add_parser("qa", help="Benchmark small models")
|
|
qa_p.add_argument("models", nargs="+", help="Model IDs to benchmark")
|
|
qa_p.add_argument("--api-key", default=None)
|
|
qa_p.add_argument("-v", "--verbose", action="store_true")
|
|
|
|
# ── add ──────────────────────────────────────────────────────────
|
|
add_p = sub.add_parser("add", help="Add a task to the queue")
|
|
add_p.add_argument("action", choices=["EDIT", "CREATE", "DELETE", "TEST"], help="Task action")
|
|
add_p.add_argument("filepath", help="Target file")
|
|
add_p.add_argument("target", help="Function name, or - for whole file")
|
|
add_p.add_argument("instruction", help="What to do (quoted string)")
|
|
add_p.add_argument("--queue", default="QUEUE.md", help="Queue file to append to")
|
|
|
|
# ── plan ─────────────────────────────────────────────────────────
|
|
plan_p = sub.add_parser("plan", help="Decompose a feature into a task queue (uses big model)")
|
|
plan_p.add_argument("description", help="Feature description in plain English")
|
|
plan_p.add_argument(
|
|
"--model",
|
|
default=os.environ.get("TINYCLAW_PLAN_MODEL", "anthropic/claude-sonnet-4-5"),
|
|
help="Planning model (should be a big model)",
|
|
)
|
|
plan_p.add_argument("--queue", default="QUEUE.md", help="Output queue file")
|
|
plan_p.add_argument("--api-key", default=None, help="API key")
|
|
plan_p.add_argument("--context", default=None, help="Path to context file (e.g. ARCH.md)")
|
|
|
|
args = parser.parse_args()
|
|
|
|
if args.command is None:
|
|
parser.print_help()
|
|
sys.exit(1)
|
|
|
|
# ── dispatch ─────────────────────────────────────────────────────
|
|
if args.command == "run":
|
|
config = RunConfig(
|
|
queue_path=args.queue,
|
|
model=args.model,
|
|
api_base=args.api_base,
|
|
api_key=args.api_key,
|
|
max_tokens=args.max_tokens,
|
|
temperature=args.temperature,
|
|
dry_run=args.dry_run,
|
|
verbose=args.verbose,
|
|
auto_commit=not args.no_commit,
|
|
)
|
|
try:
|
|
run(config)
|
|
except FileNotFoundError as e:
|
|
print(f"Error: {e}", file=sys.stderr)
|
|
sys.exit(1)
|
|
except KeyboardInterrupt:
|
|
print("\nInterrupted.")
|
|
sys.exit(130)
|
|
|
|
elif args.command == "status":
|
|
print(status(args.queue))
|
|
|
|
elif args.command == "web":
|
|
from tinyclaw.webui import serve
|
|
serve(queue_path=args.queue, history_path=args.history, host=args.host, port=args.port)
|
|
|
|
elif args.command == "qa":
|
|
from tinyclaw.qa import run_qa
|
|
run_qa(args.models, api_key=args.api_key, verbose=args.verbose)
|
|
|
|
elif args.command == "add":
|
|
_run_add(args)
|
|
|
|
elif args.command == "plan":
|
|
_run_plan(args)
|
|
|
|
|
|
def _run_add(args) -> None:
|
|
"""Append a single task to QUEUE.md."""
|
|
from pathlib import Path
|
|
line = f'{args.action} {args.filepath} {args.target} "{args.instruction}"\n'
|
|
p = Path(args.queue)
|
|
if not p.exists():
|
|
p.write_text("# TinyClaw task queue\n")
|
|
with p.open("a") as fh:
|
|
fh.write(line)
|
|
print(f"Added to {args.queue}: {line.strip()}")
|
|
|
|
|
|
def _run_plan(args) -> None:
|
|
"""Call a big model to decompose a feature into QUEUE.md tasks."""
|
|
from pathlib import Path
|
|
from tinyclaw.client import generate
|
|
|
|
context = ""
|
|
if args.context and Path(args.context).exists():
|
|
context = Path(args.context).read_text()
|
|
|
|
system = """You are a senior software engineer breaking down feature requests into atomic code tasks.
|
|
|
|
Output ONLY a QUEUE.md task list in this exact format:
|
|
EDIT <file> <function_name> "<what to change>"
|
|
CREATE <file> - "<what to create>"
|
|
DELETE <file> <function_name> "<why>"
|
|
TEST <file> - "<pytest command or describe what to test>"
|
|
|
|
Rules:
|
|
- One task per line, no blank lines between tasks
|
|
- Each task touches exactly one function (or creates one new file)
|
|
- Instructions must be concrete and actionable, 10 words or less
|
|
- No explanations, no headers, just the task list"""
|
|
|
|
user = f"Feature: {args.description}"
|
|
if context:
|
|
user += f"\n\nProject context:\n{context[:2000]}"
|
|
|
|
print(f"Planning with {args.model}...")
|
|
print(f"Feature: {args.description}\n")
|
|
|
|
resp = generate(
|
|
prompt=user,
|
|
model=args.model,
|
|
system=system,
|
|
api_key=args.api_key,
|
|
max_tokens=2048,
|
|
temperature=0.3,
|
|
)
|
|
|
|
queue_path = Path(args.queue)
|
|
if queue_path.exists():
|
|
existing = queue_path.read_text().strip()
|
|
if existing:
|
|
print(f"Appending to existing {args.queue}")
|
|
queue_path.write_text(existing + "\n" + resp.content.strip() + "\n")
|
|
else:
|
|
queue_path.write_text(resp.content.strip() + "\n")
|
|
else:
|
|
queue_path.write_text(resp.content.strip() + "\n")
|
|
|
|
print(resp.content)
|
|
print(f"\nWritten to {args.queue}")
|
|
if resp.cost:
|
|
print(f"Cost: ${resp.cost:.4f}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|