Skip to content
pi-c Artifact [4ea0b8707d]
Login

Artifact [4ea0b8707d]

Artifact 4ea0b8707d508f1072e2d0a6174314d4a0897a23d86e50bc8370adbbc76ae2a9:


#!/bin/sh
# Skills through the command line: skill folders symlinked into ~/.pic/skills
# are listed in the system prompt the server receives, the workspace's only
# once it is trusted, /skill:name expands in pic ask and pic chat, a skill
# that vanished (a dangling symlink) is not listed, and pic skills lists them.
set -eu
PIC=${PIC:?set PIC to the pic binary}
SERVER=${SERVER:?set SERVER to the fake_server binary}
S=$(cd "$(dirname "$0")/streams" && pwd)
T=$(mktemp -d "${TMPDIR:-/tmp}/pic-skills.XXXXXX")
spid=
cleanup() { [ -n "$spid" ] && kill "$spid" 2>/dev/null; rm -rf -- "$T"; }
trap cleanup EXIT HUP INT TERM
fail() { printf 'FAIL: %s\n' "$*" >&2; exit 1; }
export HOME="$T/home" ANTHROPIC_API_KEY=pic-skills-test-key PIC_PI_EXPORT=0 PIC_MODEL_CATALOG=offline
mkdir -p "$T/ws/.pic/skills" "$T/log" "$HOME/.pic/skills" "$T/store/alpha" "$T/store/beta" "$T/store/proj"
# Exact request shapes below: prompt caching (provider.sh) is off here.
"$PIC" settings cacheRetention none > /dev/null
"$SERVER" "$T/port" "$T/log" 120 "sse:$S/text.sse" "sse:$S/text.sse" "sse:$S/text.sse" "sse:$S/text.sse" \
    "sse:$S/text.sse" "sse:$S/text.sse" "sse:$S/text.sse" &
spid=$!
i=0
while [ ! -s "$T/port" ]; do i=$((i + 1)); [ "$i" -lt 100 ] || fail "server"; sleep 0.05; done
printf '{"providers":{"fake":{"baseUrl":"http://127.0.0.1:%s","api":"anthropic-messages","apiKey":"$ANTHROPIC_API_KEY","models":[{"id":"m"}]}}}' \
    "$(cat "$T/port")" > "$T/models.json"
export PIC_MODELS_FILE="$T/models.json"
pic() { "$PIC" --db "$T/j" --workspace "$T/ws" --model fake/m "$@"; }
has() { grep -qF -- "$2" "$T/log/$1.req" || fail "request $1 lacks: $2 ($(cut -c1-300 "$T/log/$1.req"))"; }
lacks() { ! grep -qF -- "$2" "$T/log/$1.req" || fail "request $1 has: $2"; }

printf -- '---\nname: alpha\ndescription: Alpha does <things> & more\n---\n\n# Alpha\nDo alpha steps.\n' > "$T/store/alpha/SKILL.md"
printf -- '---\ndescription: Beta is command only\ndisable-model-invocation: true\n---\nBeta steps\n' > "$T/store/beta/SKILL.md"
printf -- '---\ndescription: Project skill\n---\nProject steps\n' > "$T/store/proj/SKILL.md"
ln -s "$T/store/alpha" "$HOME/.pic/skills/alpha"
ln -s "$T/store/beta" "$HOME/.pic/skills/beta"
ln -s "$T/store/proj" "$T/ws/.pic/skills/proj"

pic ask 'hello' > /dev/null 2>&1 || fail "ask hello"
has 1 'The following skills provide specialized instructions for specific tasks.\nUse the read tool to load'
has 1 '<available_skills>\n  <skill>\n    <name>alpha</name>\n    <description>Alpha does &lt;things&gt; &amp; more</description>\n    <location>'
has 1 "$HOME/.pic/skills/alpha/SKILL.md</location>"
lacks 1 '<name>beta</name>'
lacks 1 '<name>proj</name>'
printf 'PASS: symlinked user skills are listed in the system prompt, a hidden one is not\n'

pic ask 'hello again' > /dev/null 2>&1 || fail "ask untrusted"
lacks 2 '<name>proj</name>'
pic trust yes > /dev/null
pic ask 'hello once more' > /dev/null 2>&1 || fail "ask trusted"
has 3 '<name>proj</name>'
printf 'PASS: a project skill is listed only once the workspace is trusted\n'

pic ask '/skill:alpha fix the bug' > /dev/null 2>&1 || fail "ask skill"
has 4 "<skill name=\\\"alpha\\\" location=\\\"$HOME/.pic/skills/alpha/SKILL.md\\\">\\nReferences are relative to $HOME/.pic/skills/alpha.\\n\\n# Alpha\\nDo alpha steps.\\n</skill>\\n\\nfix the bug"
lacks 4 'description: Alpha'
printf 'PASS: /skill:name expands in pic ask, frontmatter stripped, arguments after\n'

printf '/skill:beta\n' | pic chat > "$T/chat.out" 2>&1 || fail "chat: $(cat "$T/chat.out")"
has 5 '<skill name=\"beta\"'
has 5 'Beta steps\n</skill>'
printf 'PASS: pic chat expands a hidden skill\n'

pic skills > "$T/list" 2>&1 || fail "skills"
[ "$(wc -l < "$T/list" | tr -d ' ')" = 3 ] || fail "skills list: $(cat "$T/list")"
grep -q "^alpha	user	Alpha does <things> & more	$HOME/.pic/skills/alpha/SKILL.md\$" "$T/list" || fail "skills row: $(cat "$T/list")"
grep -q '^proj	project	Project skill	' "$T/list" || fail "skills project row"
pic skills --json | grep -q '"name":"beta","scope":"user","description":"Beta is command only","path":".*","disableModelInvocation":true' \
    || fail "skills --json"
printf 'PASS: pic skills lists name, scope, description, path\n'

rm -rf "$T/store/alpha"
pic skills > "$T/list" 2>&1 || fail "skills after vanish"
! grep -q '^alpha' "$T/list" || fail "a vanished skill is listed"
pic ask '/skill:alpha later' > /dev/null 2>&1 || fail "ask vanished"
has 6 '/skill:alpha later'
lacks 6 '<name>alpha</name>'
printf 'PASS: a vanished skill is skipped, and its command passes through\n'

# Ignore files, as Pi: .gitignore/.ignore/.fdignore in the skills folder (and
# nested ones) hide skill folders; negation brings one back.
mkdir -p "$T/store/hidden" "$T/store/shown" "$T/store/loud"
printf -- '---\ndescription: Hidden\n---\nx\n' > "$T/store/hidden/SKILL.md"
printf -- '---\ndescription: Shown\n---\nx\n' > "$T/store/shown/SKILL.md"
printf -- '---\ndescription: Loud\n---\nx\n' > "$T/store/loud/SKILL.md"
ln -s "$T/store/hidden" "$HOME/.pic/skills/hidden"
ln -s "$T/store/shown" "$HOME/.pic/skills/shown"
ln -s "$T/store/loud" "$HOME/.pic/skills/loud"
printf '# a comment\nhid*/\nloud\n!loud\n' > "$HOME/.pic/skills/.gitignore"
pic skills > "$T/list" 2>&1 || fail "skills with ignore"
! grep -q '^hidden' "$T/list" || fail "an ignored skill is listed: $(cat "$T/list")"
grep -q '^shown	' "$T/list" || fail "a skill not ignored is missing"
grep -q '^loud	' "$T/list" || fail "a negated skill is missing"
printf 'PASS: an ignored skill folder is not listed, negation restores one\n'