#!/usr/bin/env sh
set -eu

repo_root="$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)"
commit_id="${1:-}"

mkdir -p "$repo_root/skills/hwlab-agent-runtime/references"
mkdir -p "$repo_root/skills/hwlab-agent-runtime/assets"

cat > "$repo_root/skills/hwlab-agent-runtime/SKILL.md" <<EOF
---
name: hwlab-agent-runtime
description: Build and validate the HWLAB agent-mgr and agent-worker runtime skeleton, including session lifecycle, workspace volume bookkeeping, trace events, evidence records, and explicit skills commitId handling.
---

# HWLAB Agent Runtime

Use this skill when working on HWLAB agent runtime skeletons.

- Keep the control plane long-lived and worker execution session-scoped.
- Model the lifecycle as create, start, trace, finish, cleanup.
- Always carry explicit evidence record fields through the run plan.
- Use repo-local skills artifacts only when a commitId is supplied explicitly.
- Do not infer or fall back to external skill sources.
EOF

cat > "$repo_root/skills/hwlab-agent-runtime/references/runtime.md" <<EOF
# Runtime Notes

- agent-mgr owns session creation and trace emission.
- agent-worker owns worker session execution and cleanup.
- Each agent session gets its own workspace volume identity.
- Evidence records must expose projectId, operationId, kind, uri, sha256, serviceId, environment, and createdAt.
- Skills deployment artifacts require an explicit commitId.
EOF

if [ -n "$commit_id" ]; then
  printf '%s\n' "$commit_id" > "$repo_root/skills/hwlab-agent-runtime/.commit-id"
fi

echo "HWLAB skills directory ready: $repo_root/skills/hwlab-agent-runtime"
