perf(kyberforge): scope skill-frontmatter to .apm/ and parallelize plugin sync
skill-frontmatter's files: pattern matched any SKILL.md, so it ran twice per sync -- once on the .apm/ source and again on the compiled flat-mirror copy. Scoped it to .apm/skills/ like its sibling hooks (skill-size-check, vale-audit-prefilter-skill), which already only check the source. sync-plugin-content.sh ran `apm pack` once per plugin, serially -- each invocation is dominated by fixed CLI startup cost rather than per-plugin work, so 6 plugins paid that cost 6 times over (~3.1s). Backgrounds the per-plugin work instead, buffering each plugin's output so concurrent DRIFT/FAIL messages can't interleave, then flushes in stable order after `wait` (~1.3s, confirmed idempotent on a real sync). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01X7GvKuJfy2WrdBmUttV4DT
This commit is contained in:
@@ -149,7 +149,7 @@ repos:
|
||||
description: Ensure SKILL.md files have required frontmatter fields
|
||||
entry: bash
|
||||
language: system
|
||||
files: 'SKILL\.md$'
|
||||
files: '^plugins/[^/]+/\.apm/skills/[^/]+/SKILL\.md$'
|
||||
args:
|
||||
- -c
|
||||
- |
|
||||
|
||||
@@ -117,12 +117,17 @@ sync_hooks_json() {
|
||||
printf '%s\n' "$(cat "$src")" >"$dst"
|
||||
}
|
||||
|
||||
# Runs entirely inside a backgrounded subshell (see the dispatch loop below), so
|
||||
# FAIL here is that subshell's own copy -- it never touches the parent's FAIL
|
||||
# and must be handed back via status_file instead.
|
||||
sync_one() {
|
||||
local plugin_dir="${1%/}"
|
||||
local plugin_dir="${1%/}" status_file="$2"
|
||||
local apm_dir="$plugin_dir/.apm"
|
||||
FAIL=0
|
||||
|
||||
if [[ ! -d "$apm_dir" ]]; then
|
||||
echo "SKIP $plugin_dir: no .apm/ directory" >&2
|
||||
echo "$FAIL" >"$status_file"
|
||||
return 0
|
||||
fi
|
||||
|
||||
@@ -140,6 +145,7 @@ sync_one() {
|
||||
sed 's/^/ /' "$pack_log" >&2
|
||||
rm -f "$pack_log"
|
||||
FAIL=1
|
||||
echo "$FAIL" >"$status_file"
|
||||
return 0
|
||||
fi
|
||||
rm -f "$pack_log"
|
||||
@@ -148,6 +154,7 @@ sync_one() {
|
||||
if [[ -z "$bundle_dir" ]]; then
|
||||
echo "FAIL $plugin_dir: apm pack produced no bundle directory under $scratch" >&2
|
||||
FAIL=1
|
||||
echo "$FAIL" >"$status_file"
|
||||
return 0
|
||||
fi
|
||||
|
||||
@@ -156,10 +163,26 @@ sync_one() {
|
||||
sync_dir "$plugin_dir" "$bundle_dir" "$d"
|
||||
done
|
||||
sync_hooks_json "$plugin_dir" "$bundle_dir"
|
||||
echo "$FAIL" >"$status_file"
|
||||
}
|
||||
|
||||
for plugin_dir in "$@"; do
|
||||
sync_one "$plugin_dir"
|
||||
# Each plugin's `apm pack` is an independent CLI invocation dominated by fixed
|
||||
# process-startup cost, not by per-plugin work -- run them concurrently rather
|
||||
# than paying that startup cost N times serially. Output is buffered per plugin
|
||||
# (not streamed) so concurrent DRIFT/FAIL messages from different plugins never
|
||||
# interleave; it's flushed in stable $@ order once every job has finished.
|
||||
declare -a plugin_dirs=("$@")
|
||||
for plugin_dir in "${plugin_dirs[@]}"; do
|
||||
name="$(basename "${plugin_dir%/}")"
|
||||
(sync_one "$plugin_dir" "$SCRATCH_ROOT/$name.status") >"$SCRATCH_ROOT/$name.log" 2>&1 &
|
||||
done
|
||||
wait
|
||||
|
||||
for plugin_dir in "${plugin_dirs[@]}"; do
|
||||
name="$(basename "${plugin_dir%/}")"
|
||||
cat "$SCRATCH_ROOT/$name.log" >&2
|
||||
status="$(cat "$SCRATCH_ROOT/$name.status" 2>/dev/null || echo 1)"
|
||||
[[ "$status" -ne 0 ]] && FAIL=1
|
||||
done
|
||||
|
||||
if [[ "$FAIL" -ne 0 ]]; then
|
||||
|
||||
Reference in New Issue
Block a user