The meta-skill that builds and improves all your skills, including itself. Watches your work sessions (autonomous or human-led), captures patterns, corrections and judgement calls, and turns them into skill improvements and new skill candidates for your review. Practical application of the Augmented Expertise methodology. Open source: CC BY 4.0.
Python agent-skillsai-skillsaugmented-expertiseawesome-skillsclaudeclaude-codeclaude-code-skillclaude-code-skillsclaude-coworkclaude-skillsmeta-skillrebelyticsskill-automationskill-builderskill-creationskill-improvementskill-managementskills
Helper: claim each id atomically, never overwrite an archived file
Eoghan Henn856a1a2fab62
diff --git a/SKILL.md b/SKILL.mdindex b83da2b..ecb59a6 100644--- a/SKILL.md+++ b/SKILL.md@@ -403,7 +403,7 @@ seen=$(cd "$d" && awk 'FNR==1 {n++; nextfile} END {print n+0}' *.md 2>/dev/null)( cd "$d" && awk -v today="$today" 'FNR==1 {st=""; r=""; fm=/^---[[:space:]]*$/; if (!fm) nextfile; next}fm && /^---[[:space:]]*$/ {if (st ~ /^(actioned|declined|superseded)$/ && r ~ /^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$/ && r < today) print FILENAME; nextfile}fm && /^status:/ {st=$2}- fm && /^resolved:/ {r=$2}' *.md 2>/dev/null | while IFS= read -r x; do mv "$x" archive/; done ) # one awk for the set, one mv per stale resolved file; bash+ fm && /^resolved:/ {r=$2}' *.md 2>/dev/null | while IFS= read -r x; do mv -n "$x" archive/ 2>/dev/null; if [ -e "$x" ]; then echo "NOTE: $x not archived — archive/$x exists or the move failed"; fi; done ) # one awk for the set, one mv per stale resolved file, never over an archived one; bashfloor=$(sed '1!d; s/[^0-9]//g' "$d/archive/.id-floor" 2>/dev/null); floor=$((10#${floor:-0})) # digits only: a CRLF or padded floor still readsids=$(for p in "$d"/[0-9]*.md "$d"/archive/[0-9]*.md; do [ -e "$p" ] && printf '%s\n' "${p##*/}"; done | grep -oE '^[0-9]+') # globs and builtins: no `ls` a profile alias can rebind[ "$(printf '%s' "$ids" | grep -c .)" -eq "$(find "$d" "$d/archive" -maxdepth 1 -name '[0-9]*.md' | wc -l)" ] || { echo "ID COMMAND BROKEN — the listing and find disagree on the prefixed files"; exit 1; }diff --git a/references/observation-log.md b/references/observation-log.mdindex 3f64dae..a939004 100644--- a/references/observation-log.md+++ b/references/observation-log.md@@ -972,7 +972,7 @@ seen=$(cd "$d" && awk 'FNR==1 {n++; nextfile} END {print n+0}' *.md 2>/dev/null)( cd "$d" && awk -v today="$today" 'FNR==1 {st=""; r=""; fm=/^---[[:space:]]*$/; if (!fm) nextfile; next}fm && /^---[[:space:]]*$/ {if (st ~ /^(actioned|declined|superseded)$/ && r ~ /^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$/ && r < today) print FILENAME; nextfile}fm && /^status:/ {st=$2}- fm && /^resolved:/ {r=$2}' *.md 2>/dev/null | while IFS= read -r x; do mv "$x" archive/; done ) # one awk for the set, one mv per stale resolved file; bash+ fm && /^resolved:/ {r=$2}' *.md 2>/dev/null | while IFS= read -r x; do mv -n "$x" archive/ 2>/dev/null; if [ -e "$x" ]; then echo "NOTE: $x not archived — archive/$x exists or the move failed"; fi; done ) # one awk for the set, one mv per stale resolved file, never over an archived one; bashfloor=$(sed '1!d; s/[^0-9]//g' "$d/archive/.id-floor" 2>/dev/null); floor=$((10#${floor:-0})) # digits only: a CRLF or padded floor still readsids=$(for p in "$d"/[0-9]*.md "$d"/archive/[0-9]*.md; do [ -e "$p" ] && printf '%s\n' "${p##*/}"; done | grep -oE '^[0-9]+') # globs and builtins: no `ls` a profile alias can rebind[ "$(printf '%s' "$ids" | grep -c .)" -eq "$(find "$d" "$d/archive" -maxdepth 1 -name '[0-9]*.md' | wc -l)" ] || { echo "ID COMMAND BROKEN — the listing and find disagree on the prefixed files"; exit 1; }@@ -991,7 +991,12 @@ prefix echoed.**`bash scripts/new-observation.sh <slug> [workspace-root]` is this snippet asone command.** It performs the same steps in the same order — sweep, id,-prefix guard, noclobber create, floor write — takes the pinned workspace+prefix guard, noclobber create, floor write — plus one the inline snippet+lacks: before the prefix guard it claims the number with a noclobber+create of an empty marker in `archive/.id-claims/`, moving up one when the+claim is taken, so two runs at the same moment never share an id. Markers+are never removed (no delete permission needed); one left by an+interrupted run only leaves a gap. It takes the pinned workspaceroot as its second argument or from `TASK_OBSERVER_WORKSPACE`, refuses arelative root, a malformed slug or a missing `observation-log/archive/`(halt and re-probe; never recreate from a writer), and prints the created@@ -1110,11 +1115,14 @@ path, the invariant is a unique number, and a guard on the path passesevery violation of the number that uses a different slug — which is allof them. So the guard now asks whether any file with the derived prefixexists in `observation-log/` or `archive/` (`find … -name 'NNNN-*.md'`,-never a bare glob), and halts if one does. It fires only when the-derivation is stale — a correct max-of-three cannot produce a number that-is already in use — so a COLLISION here means the id came from somewhere-other than a snippet run immediately before this write. Re-run the-snippet; never adjust the number by hand.+never a bare glob), and halts if one does. It fires when the derivation+is stale — the id came from somewhere other than a snippet run+immediately before this write. It cannot see a writer running at the same+moment, whose file does not exist yet: both derive the same correct+number from the same listing. The script closes that window with its+number claim; the inline snippet does not, and the review's duplicate-id+check catches what slips through. Re-run the snippet; never adjust the+number by hand.### Run the snippet immediately before every write@@ -1247,7 +1255,8 @@ write-back once silently erased entries appended minutes earlier. None ofthose failure modes exist when each file is isolated. In the rare case twoparallel sessions pick the same id, the result is two files sharing anumber — harmless, distinct files, nothing lost, as long as the slugs-differ; the snippet's prefix guard catches that case at write time when the+differ; the script's number claim prevents it for runs at the same moment,+the snippet's prefix guard catches it at write time when thederivation is stale, an identical id AND slug is one path, which is what the`noclobber` create guards against, and the review's duplicate-id check (Step1, re-run at Step 6) renumbers whatever slips past both and logs adiff --git a/scripts/new-observation.sh b/scripts/new-observation.shindex 7d6bef9..afb6999 100755--- a/scripts/new-observation.sh+++ b/scripts/new-observation.sh@@ -16,20 +16,23 @@# created. Write the observation body into the printed path, with the id# from its NNNN- prefix in the `id:` field — copied, never retyped.#-# This is the id-derivation snippet from SKILL.md "How to Log", unchanged in-# substance, packaged so that the moment of derivation cannot drift away-# from the moment of writing: an id derived at session start and carried in-# memory to a later write is the collision the snippet's rules forbid, and-# a rule that has failed twice while loaded needs the write path itself to-# enforce it. Where this script can run, it is the only write path.+# This is the id-derivation snippet from SKILL.md "How to Log", plus a+# number claim the inline snippet lacks, packaged so that the moment of+# derivation cannot drift away from the moment of writing: an id derived+# at session start and carried in memory to a later write is the collision+# the snippet's rules forbid, and a rule that has failed twice while loaded+# needs the write path itself to enforce it. Where this script can run, it+# is the only write path.## Steps, in order: archival sweep of stale resolved files (a side effect of-# deriving the id, never a separate duty) → id = max(active prefixes,-# archive prefixes, .id-floor) + 1, the listing guarded against find's-# count before the floor enters → PREFIX collision guard across active and-# archive (two slugs sharing one number is the failure; a path check cannot-# see it) → noclobber create → floor write (after the create, so a run that-# creates nothing never moves it) → print the path.+# deriving the id, never a separate duty; a same-named archived file is+# never overwritten) → id = max(active prefixes, archive prefixes,+# .id-floor) + 1, the listing guarded against find's count before the floor+# enters → number claim (a noclobber marker per id in archive/.id-claims/,+# so two writers running at once never share one) → PREFIX collision guard+# across active and archive (two slugs sharing one number is the failure; a+# path check cannot see it) → noclobber create → floor write (after the+# create, so a run that creates nothing never moves it) → print the path.## bash, not sh: the `10#` arithmetic is a bash extension. Runs on bash 3.2# (stock macOS): case patterns are parenthesised for that reason.@@ -76,17 +79,30 @@ fi( cd "$d" && awk -v today="$today" 'FNR==1 {st=""; r=""; fm=/^---[[:space:]]*$/; if (!fm) nextfile; next}fm && /^---[[:space:]]*$/ {if (st ~ /^(actioned|declined|superseded)$/ && r ~ /^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$/ && r < today) print FILENAME; nextfile}fm && /^status:/ {st=$2}- fm && /^resolved:/ {r=$2}' *.md 2>/dev/null | while IFS= read -r x; do mv "$x" archive/; done )+ fm && /^resolved:/ {r=$2}' *.md 2>/dev/null | while IFS= read -r x; do+ mv -n "$x" archive/ 2>/dev/null # -n: never overwrite a same-named archived file+ if [ -e "$x" ]; then+ if [ -e "archive/$x" ]; then echo "NOTE: $x not archived — archive/$x already exists; compare the two copies by hand" >&2+ else echo "NOTE: $x not archived — the move failed" >&2; fi+ fi+ done )# --- id: max of active prefixes, archive prefixes and the floor, plus one ---# Globs and builtins list the files, never `ls`: a profile alias or function# can rebind that word. The floor is read as digits only (a CRLF or padded# file still reads), and 10# keeps a zero-padded number out of octal.floor=$(sed '1!d; s/[^0-9]//g' "$d/archive/.id-floor" 2>/dev/null); floor=$((10#${floor:-0}))-ids=$(for p in "$d"/[0-9]*.md "$d"/archive/[0-9]*.md; do [ -e "$p" ] && printf '%s\n' "${p##*/}"; done | grep -oE '^[0-9]+')-if [ "$(printf '%s' "$ids" | grep -c .)" -ne "$(find "$d" "$d/archive" -maxdepth 1 -name '[0-9]*.md' | wc -l)" ]; then- echo "ID COMMAND BROKEN — the listing and find disagree on the prefixed files" >&2; exit 1-fi+# Up to three attempts, a second apart: a writer running at the same moment+# can create a file between the listing and find's count; a broken listing+# disagrees every time.+for attempt in 1 2 3; do+ ids=$(for p in "$d"/[0-9]*.md "$d"/archive/[0-9]*.md; do [ -e "$p" ] && printf '%s\n' "${p##*/}"; done | grep -oE '^[0-9]+')+ [ "$(printf '%s' "$ids" | grep -c .)" -eq "$(find "$d" "$d/archive" -maxdepth 1 -name '[0-9]*.md' | wc -l)" ] && break+ if [ "$attempt" -eq 3 ]; then+ echo "ID COMMAND BROKEN — the listing and find disagree on the prefixed files" >&2; exit 1+ fi+ sleep 1+donehi=$(printf '%s\n' "$ids" | sort -n | tail -1); hi=$((10#${hi:-0}))if [ "$hi" -lt "$floor" ]; thenecho "NOTE: highest file id $hi is below .id-floor $floor — ids issued without a file; the new id goes above the floor" >&2@@ -99,10 +115,30 @@ prefix=$(printf '%04d' "$next_id")# because a lagging floor is the precondition for a restart once the active# directory is archived down.top_active=$(for p in "$d"/[0-9]*.md; do [ -e "$p" ] && printf '%s\n' "${p##*/}"; done | grep -oE '^[0-9]+' | sort -n | tail -1)-if [ -s "$d/archive/.id-floor" ] && [ -n "${top_active:-}" ] && [ "$floor" -lt "$((10#$top_active))" ]; then+if [ -s "$d/archive/.id-floor" ] && [ -n "${top_active:-}" ] && [ "$floor" -lt "$((10#$top_active))" ] \+ && [ ! -e "$d/archive/.id-claims/$(printf '%04d' "$((10#$top_active))")" ]; then # a claimed id is a writer still running, not a skipecho "NOTE: .id-floor ($floor) is below the highest active id ($((10#$top_active))) — an issuer skipped the floor write; corrected now" >&2fi+# --- claim the NUMBER atomically ---------------------------------------------+# Two writers running at once derive the same number from the same listing,+# and the guard below cannot see a file the other has not created yet. The+# claim is a noclobber create of an empty marker named by the number alone,+# so exactly one writer gets each number; the other moves up one and tries+# again. Markers are never removed (nothing here needs delete permission),+# and a marker left by a run that stopped before its create only leaves a+# gap in the ids.+c="$d/archive/.id-claims"+mkdir -p "$c" || { echo "CLAIM DIR FAILED — cannot create '$c'" >&2; exit 1; }+tries=0+until (set -C; : > "$c/$prefix") 2>/dev/null; do+ tries=$((tries + 1))+ if [ "$tries" -ge 100 ]; then+ echo "CLAIM FAILED — 100 consecutive numbers up to $next_id already claimed under '$c'" >&2; exit 1+ fi+ next_id=$((next_id + 1)); prefix=$(printf '%04d' "$next_id")+done+# --- collision guard on the id PREFIX, across active and archive ------------# Two writers deriving the same number with different slugs produce two# different paths; a path check passes both. The invariant is a unique@@ -118,6 +154,10 @@ if ! (set -C; : > "$f") 2>/dev/null; thenfi# --- floor write, after the create: never lower (next_id > floor) -------------printf '%s\n' "$next_id" > "$d/archive/.id-floor" || { echo "FLOOR WRITE FAILED — $d/archive/.id-floor (the file $f exists; fix the floor by hand)" >&2; exit 1; }+# The floor takes the highest CLAIMED number, not only this run's: a writer+# that finished first must not be left above the floor by a slower one.+top_claim=$(for p in "$c"/[0-9]*; do [ -e "$p" ] && printf '%s\n' "${p##*/}"; done | sort -n | tail -1)+top_claim=$((10#${top_claim:-0})); [ "$top_claim" -gt "$next_id" ] || top_claim=$next_id+printf '%s\n' "$top_claim" > "$d/archive/.id-floor" || { echo "FLOOR WRITE FAILED — $d/archive/.id-floor (the file $f exists; fix the floor by hand)" >&2; exit 1; }printf '%s\n' "$f"