#!/bin/sh
# A tree of session files for timing the usage scan (docs/evidence.md): FILES files
# (default 200) under DIR/projects/-gen-N/, each about 1 MiB, with two lines of
# about 512 KiB that look like an embedded image, and a skill, an agent and a
# command in each. Made-up names; nothing here is a real record.
# usage: make_usage_tree.sh DIR [FILES]
set -eu
dir=${1:?usage: make_usage_tree.sh DIR [FILES]}
files=${2:-200}
mkdir -p "$dir/projects" "$dir/tmp"
pad=$dir/tmp/pad
awk 'BEGIN { srand(7); a = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
    for (i = 0; i < 8192; i++) { s = ""; for (j = 0; j < 64; j++) s = s substr(a, int(rand() * 64) + 1, 1); printf "%s", s } }' >"$pad"
big_head='{"type":"user","message":{"role":"user","content":[{"type":"tool_result","tool_use_id":"toolu_gen","content":[{"type":"image","source":{"type":"base64","media_type":"image/png","data":"'
big_tail='"}}]}]},"timestamp":"2026-11-10T10:00:00.000Z","cwd":"/work/gen"}'
n=1
while [ "$n" -le "$files" ]; do
    d=$dir/projects/-gen-$((n % 10))
    mkdir -p "$d"
    f=$d/session-$n.jsonl
    {
        printf '{"type":"assistant","message":{"content":[{"type":"tool_use","id":"toolu_s%s","name":"Skill","input":{"skill":"gen-skill-%s"}}]},"timestamp":"2026-11-10T10:00:00.000Z","cwd":"/work/gen"}\n' "$n" "$((n % 17))"
        printf '%s' "$big_head"; cat "$pad"; printf '%s\n' "$big_tail"
        printf '{"type":"assistant","message":{"content":[{"type":"tool_use","id":"toolu_a%s","name":"Agent","input":{"subagent_type":"gen-agent-%s"}}]},"timestamp":"2026-11-10T10:01:00.000Z","cwd":"/work/gen"}\n' "$n" "$((n % 5))"
        printf '%s' "$big_head"; cat "$pad"; printf '%s\n' "$big_tail"
        printf '{"type":"user","message":{"role":"user","content":"<command-name>/gen-command-%s</command-name>"},"timestamp":"2026-11-10T10:02:00.000Z","cwd":"/work/gen"}\n' "$((n % 3))"
    } >"$f"
    n=$((n + 1))
done
rm -rf "$dir/tmp"
