Skip to content

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.

Create each observation as a filled header, never an empty file

Eoghan Henn3df3a1fe631e
diff --git a/references/environments.md b/references/environments.md
index 7280d34..146b76e 100644
--- a/references/environments.md
+++ b/references/environments.md
@@ -633,11 +633,11 @@ one), before trusting either outcome.
path" is a rule, and a rule broken twice needs a barrier (SKILL.md, the
second-violation rule): a direct create with the editing tool skips the
id derivation and the prefix collision guard, and two ids each used twice
-are what that looks like afterwards. The helper creates the file with a
-`noclobber` create before any body is written, so a pre-tool hook can
-refuse every editing-tool write that would CREATE a Markdown file in the
-log, and the helper's own two-step write (create, then fill) passes
-untouched. Node, no dependencies; substitute `[ABSOLUTE PATH]` as
+are what that looks like afterwards. The helper creates the file — a
+frontmatter skeleton carrying the id — with a `noclobber` create before
+any body is written, so a pre-tool hook can refuse every editing-tool
+write that would CREATE a Markdown file in the log, and the fill of the
+skeleton the helper made passes untouched. Node, no dependencies; substitute `[ABSOLUTE PATH]` as
elsewhere, and register it for the editing tool's write call (in Claude
Code, matcher `Write`) with the interpreter in the command, as above:
diff --git a/references/observation-log.md b/references/observation-log.md
index a0520b9..d5be763 100644
--- a/references/observation-log.md
+++ b/references/observation-log.md
@@ -478,7 +478,12 @@ or text with no opening `---` — is named on the scan's `LOST ENTRIES`
line instead: it is the trace of a write interrupted between the
`noclobber` create and the body (a denied write, a context cut, a session
ending), and it holds an id nobody may reuse. Report each in the start-up
-lines. If the observation can be reconstructed — this session wrote it,
+lines. A header whose `title:` is empty is the helper's skeleton and goes
+on the `UNFILLED` line instead — a write in progress (another session's,
+or this one's a moment ago) or an abandoned one; it already holds its id,
+so it is filled or declined the same way, never reused or deleted. A
+header whose `id:` does not read as the filename prefix is named on its
+own `NOTE:` line: fix the field after reading the body, never the name. If the observation can be reconstructed — this session wrote it,
or the slug and the session record say enough — write the body into
that file now; otherwise give it a minimal header (`id` from the prefix,
a `title` naming the slug, `status: declined`, `resolved:` today,
@@ -882,22 +887,30 @@ The snippet leaves the derived number in `$next_id` and the target path in
`$f`; append `printf '%04d\n' "$next_id"` if you also want the filename
prefix echoed.
-**`bash scripts/new-observation.sh <slug> [workspace-root]` is this snippet as
-one command.** It performs the same steps in the same order — sweep, id,
-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 workspace
-root as its second argument or from `TASK_OBSERVER_WORKSPACE`, refuses a
-relative root, a malformed slug or a missing `observation-log/archive/`
-(halt and re-probe; never recreate from a writer), and prints the created
-path on stdout. Where it can run, it is the only write path: an id that
-exists only as the script's output cannot be carried in memory from an
-earlier read to a later write, which is the drift every rule in this
-section is trying to prevent. The inline snippet remains for harnesses
-where a script cannot be invoked.
+**`bash scripts/new-observation.sh [--body <file>] <slug> [workspace-root]`
+is this snippet as one command.** It performs the same steps in the same
+order — sweep, id, 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. Its create is
+never an empty file: it writes the frontmatter skeleton — `id:` (the
+number, unpadded), `date:`, `status: open`, every other field present and
+empty — so the id is on disk before anything can retype it and a scan
+that meets the file mid-write reports it UNFILLED (a header with an empty
+`title:`), never LOST; `--body <file>` builds the filled copy beside it
+and renames it into place, so the file holds the skeleton or the whole
+body, never a part, and a `NOTE:` on stderr names a body whose `id:` is
+not the one issued. It takes the pinned workspace root as its second
+argument or from `TASK_OBSERVER_WORKSPACE`, refuses a relative root, a
+malformed slug or a missing `observation-log/archive/` (halt and
+re-probe; never recreate from a writer), and prints the created path on
+stdout. Where it can run, it is the only write path: an id that exists
+only as the script's output cannot be carried in memory from an earlier
+read to a later write, which is the drift every rule in this section is
+trying to prevent. The inline snippet remains for harnesses where a
+script cannot be invoked.
The `10#` prefix in the arithmetic is load-bearing, not cosmetic: shell
arithmetic reads a leading-zero number as octal, so `$(( 0105 + 1 ))`
@@ -1194,7 +1207,7 @@ content have been replaced by the output of commands. Quote the delimiter
(`<<'OBS'`) whenever a shell write is genuinely the only path — a
`set -C` noclobber create has no editing-tool equivalent — and prefer the
editing tool everywhere else. Where the editing tool refuses to write a
-file it has not read in the session, read the empty file the create just
+file it has not read in the session, read the skeleton the create just
made before writing the body: the refusal is keyed on that state, and it
reads like a harness fault rather than a consequence of the create. A quoted heredoc is exact only where the
shell receives the command as typed; on a host whose shell tool rewrites
@@ -1426,7 +1439,7 @@ is a write: a step whose value lies in happening at a specific moment needs
its own entry in the tool record. (Where the workspace prices every write —
the exception under "How to Log" — fold this line into the session's first
write instead.) Read the scan's output whole. Its finding lines (NOTE,
-LOST ENTRIES, GAP) and counts come first and the entry headers last, with
+LOST ENTRIES, UNFILLED, GAP) and counts come first and the entry headers last, with
one `end of scan` line closing it that repeats the counts and the number
of finding lines; `tail`, `head` or a `grep` hides exactly the lines that
matter while the checkpoint line still lands and the log looks
diff --git a/scripts/new-observation.sh b/scripts/new-observation.sh
index eea0adc..70be3e3 100755
--- a/scripts/new-observation.sh
+++ b/scripts/new-observation.sh
@@ -21,9 +21,15 @@
#
# Prints the created file's absolute path on stdout (one line) and exits 0.
# Any guard firing prints its message on stderr and exits 1 with NO file
-# created. Without --body, write the observation body into the printed
-# path, with the id from its NNNN- prefix in the `id:` field — copied,
-# never retyped.
+# created. The file is never empty: the create writes a frontmatter
+# skeleton — `id:` (the number, unpadded), `date:` today, `status: open`,
+# every other field present and empty — so a scan that meets it mid-write
+# reads a header with its id, not a LOST entry, and the id is on disk
+# before anything can retype it. Without --body, fill the skeleton's
+# fields in place (the `id:` line is already right: copy nothing, retype
+# nothing) and append the body below the closing `---`. With --body, the
+# filled copy is built beside the file and renamed over it, so the file
+# holds either the skeleton or the whole body, never a part.
#
# 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
@@ -40,9 +46,11 @@
# 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) → body copy with
-# the placeholders filled (--body only) → print the path.
+# path check cannot see it) → noclobber create of the skeleton → floor
+# write (after the create, so a run that creates nothing never moves it) →
+# body copy with the placeholders filled, built as a hidden sibling and
+# renamed into place (--body only) → id check on the written header →
+# 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, and the
@@ -188,8 +196,16 @@ if [ -n "$(find "$d" -maxdepth 2 -name "${prefix}-*.md")" ]; then
fi
# --- noclobber create: never truncate an existing file ----------------------
+# The create and the first content are one printf: the file is a header
+# with its id from the first instant it exists. An empty file in the log is
+# a LOST entry by definition (the scan says so), and a create that leaves
+# one is a LOST entry for as long as the caller takes to write the body.
+# The field list mirrors the core template (How to Log); `title:` is left
+# empty on purpose — the scan reports a header with an empty title as
+# UNFILLED, a write in progress or abandoned, distinct from LOST.
f="$d/${prefix}-${slug}.md"
-if ! (set -C; : > "$f") 2>/dev/null; then
+skel=$(printf '%s\nid: %s\ntitle: ""\nstatus: open\ntype:\nskill: []\nproposes_skill: []\ntarget_file: []\nsiblings_checked: ""\narea: ""\ndate: %s\nsession_context: ""\nparked_until:\nresolved:\nresolution:\nreference:\n---' --- "$next_id" "$today") # the format opens with %s: a leading --- reads as an option
+if ! (set -C; printf '%s\n' "$skel" > "$f") 2>/dev/null; then
echo "CREATE FAILED — $f exists or is unwritable" >&2; exit 1
fi
@@ -205,11 +221,32 @@ printf '%s\n' "$top_claim" > "$d/archive/.id-floor" || { echo "FLOOR WRITE FAILE
# (no regex metacharacters in either) and the replacements are an integer
# and a YYYY-MM-DD date, so nothing needs escaping and every other byte —
# backticks, $, quotes — reaches the file verbatim. Plain `s///g`, no -i and
-# no GNU-only flag: BSD sed runs this too.
+# no GNU-only flag: BSD sed runs this too. The filled copy is built as a
+# hidden sibling (a leading dot: no `[0-9]*.md` listing or glob sees it)
+# and renamed over the skeleton, one atomic step, so no reader ever meets
+# the file truncated. Where the rename is refused (a mount that treats
+# replacing a file as a delete), the copy is written in place instead and
+# the sibling is left for the user — nothing here deletes.
if [ -n "$body" ]; then
- if ! sed -e "s/__ID__/$next_id/g" -e "s/__DATE__/$today/g" "$body" > "$f"; then
- echo "BODY COPY FAILED — $f exists and is empty; write the body into it by hand (id $next_id)" >&2; exit 1
+ part="$d/.${prefix}-${slug}.md.part"
+ if ! sed -e "s/__ID__/$next_id/g" -e "s/__DATE__/$today/g" "$body" > "$part"; then
+ echo "BODY COPY FAILED — $f holds the frontmatter skeleton only; write the body into it by hand (id $next_id)" >&2; exit 1
fi
+ if ! mv -f "$part" "$f" 2>/dev/null; then
+ if cat "$part" > "$f"; then
+ echo "NOTE: rename refused — body copied in place; remove '$part' by hand" >&2
+ else
+ echo "BODY COPY FAILED — $f holds the frontmatter skeleton only; the filled copy is at '$part' (id $next_id)" >&2; exit 1
+ fi
+ fi
+ # The id in the written header must be the one this run issued: a body
+ # that carried a literal id instead of __ID__ is the mismatch the scan
+ # reports; say so here, where the body is still in hand.
+ got=$(LC_ALL=C awk 'FNR==1 {sub(/^\357\273\277/, "")} /^---[[:space:]]*$/ {if (++n == 2) exit; next} n == 1 && /^id:/ {v=$2; gsub(/["\047\r]/, "", v); print v; exit}' "$f")
+ case $got in
+ (*[!0-9]*|"") echo "NOTE: $f carries no numeric id: in its header (read '$got'); set id: $next_id" >&2 ;;
+ (*) [ "$((10#$got))" -eq "$next_id" ] || echo "NOTE: $f carries id: $got but its prefix is $prefix — the body held a literal id; set id: $next_id" >&2 ;;
+ esac
fi
if [ -n "$pin_form" ]; then cygpath "$pin_form" "$f"; else printf '%s\n' "$f"; fi
diff --git a/scripts/session-start-scan.sh b/scripts/session-start-scan.sh
index 5f77bae..0d421d0 100755
--- a/scripts/session-start-scan.sh
+++ b/scripts/session-start-scan.sh
@@ -11,14 +11,17 @@
# required; the log is never resolved from the cwd. The
# path may contain spaces.
#
-# Prints, on stdout, in this order: any NOTE / LOST ENTRIES lines; the counts
+# Prints, on stdout, in this order: any NOTE / LOST ENTRIES / UNFILLED lines
+# (UNFILLED: a header whose title: is empty — the skeleton new-observation.sh
+# writes at create time, a write in progress or abandoned; NOTE: id: … when
+# a header's id does not read as its filename prefix); the counts
# line (files, parsed, suspect, archive-suspect); a NOTE: pointer line when
# skill-observations/MOVED.md exists; a GAP line when the previous scan in
# checkpoints.log is 7 or more days old; the logs found under the root's
# parent; the active principles' headings; then the frontmatter of every
# numbered entry, each header followed by one `---` line; and LAST one
# `end of scan` line repeating the counts and how many finding lines
-# (NOTE / LOST ENTRIES / GAP) stand above the entries. The findings open the
+# (NOTE / LOST ENTRIES / UNFILLED / GAP) stand above the entries. The findings open the
# output and the summary closes it, so a view cut by `head` keeps the
# findings and one cut by `tail` keeps the summary and its finding count;
# neither replaces reading the output whole, which the summary line says.
@@ -124,7 +127,7 @@ a_sus=0; [ -d "$d/archive" ] && a_sus=$(LC_ALL=C find "$d/archive" -maxdepth 1 -
p="$root/skill-observations/cross-cutting-principles.md"
pa='/^(\140\140\140|~~~)/ {f=!f} f {next} /^## Active Principles/ {a=1; h=1; next} a && /^## / {a=0}'
pr=absent; [ -f "$p" ] && pr=$(awk "$pa"' a && /^### / {n++} END {print (h ? n+0 : "unparsed")}' "$p")
-# fx counts the finding lines (NOTE / LOST ENTRIES / GAP) printed above the
+# fx counts the finding lines (NOTE / LOST ENTRIES / UNFILLED / GAP) printed above the
# entries, for the end-of-scan line.
fx=0
[ "$pr" = unparsed ] && { echo "NOTE: the principles file has no '## Active Principles' heading — 'could not parse', not 'no principles'; read it directly"; fx=$((fx + 1)); }
@@ -136,6 +139,21 @@ if [ "$n" -gt 0 ] && [ "$parsed" -eq 0 ]; then echo "SCAN COMMAND BROKEN — $n
# Lost entries: a zero-byte numbered file, or one with no opening `---`.
lost=$( { find "$d" -maxdepth 1 -name '[0-9]*.md' -empty; LC_ALL=C find "$d" -maxdepth 1 -name '[0-9]*.md' ! -empty -exec awk 'FNR==1 {sub(/^\357\273\277/, ""); if (!/^---[[:space:]]*$/) print FILENAME; nextfile}' {} +; } | sed 's|.*/||' | LC_ALL=C sort | tr '\n' ' ')
[ -n "$lost" ] && { echo "LOST ENTRIES — no header, an interrupted write; report each, never reuse or delete: $lost"; fx=$((fx + 1)); }
+# Unfilled and mismatched headers, from one awk over the parsed headers:
+# U <file> for a header whose title: is empty — the skeleton the helper
+# writes at create time, so a write in progress or abandoned, distinct from
+# LOST (it holds its id); I <file> <id> for a header whose id: does not
+# read as the filename prefix (a retyped id, or a body written into another
+# entry's file). The id may be padded or not — both forms exist in live
+# logs — so the comparison is numeric.
+hd=$(LC_ALL=C find "$d" -maxdepth 1 -name '[0-9]*.md' -exec awk 'FNR==1 {sub(/^\357\273\277/, ""); fm=/^---[[:space:]]*$/; ti=0; idv="none"; f=FILENAME; sub(/.*\//, "", f); pre=substr(f, 1, match(f, /[^0-9]/) - 1); if (!fm) nextfile; next}
+ fm && /^---[[:space:]]*$/ {if (ti) print "U " f; if (idv !~ /^0*[1-9][0-9]*$/ || idv + 0 != pre + 0) print "I " f " " idv; nextfile}
+ fm && /^title:/ {v=$0; sub(/^title:[[:space:]]*/, "", v); sub(/[[:space:]]+$/, "", v); ti=(v == "" || v == "\"\"" || v == "\047\047")}
+ fm && /^id:/ {idv=$2; gsub(/["\047\r]/, "", idv)}' {} +)
+unfilled=$(printf '%s\n' "$hd" | sed -n 's/^U //p' | LC_ALL=C sort | tr '\n' ' ')
+[ -n "$unfilled" ] && { echo "UNFILLED — a header with an empty title: the helper's skeleton, a write in progress or abandoned; it holds its id, so fill it or decline it, never reuse or delete: $unfilled"; fx=$((fx + 1)); }
+idmis=$(printf '%s\n' "$hd" | sed -n 's/^I \(.*\) \(.*\)$/\1 (id: \2)/p' | LC_ALL=C sort | tr '\n' ' ')
+[ -n "$idmis" ] && { echo "NOTE: id: does not read as the filename prefix — another entry's id retyped, or a body written into the wrong file; fix the field, never the filename, after reading the body: $idmis"; fx=$((fx + 1)); }
# Headers that did not parse, by name: no opening, or no closing `---`.
[ "$parsed" -lt "$n" ] && { echo "NOTE: $((n - parsed)) of $n headers did not parse (no opening or no closing ---):"; fx=$((fx + 1)); } && LC_ALL=C find "$d" -maxdepth 1 -name '[0-9]*.md' -exec awk 'FNR==1 {if (NR>1 && fm) print f; f=FILENAME; sub(/^\357\273\277/, ""); fm=/^---[[:space:]]*$/; if (!fm) {print f; nextfile}; next} fm && /^---[[:space:]]*$/ {fm=0; nextfile} END {if (fm) print f}' {} +
[ "$suspect" -gt 0 ] || [ "$a_sus" -gt 0 ] && { echo "NOTE: $suspect of $n headers (and $a_sus in archive/) look like invalid YAML (an unquoted ': ', text after a closing quote, a value opening with a backtick, @ or %, an undefined escape, a colon in an unquoted list entry) — quote or fix them (File format)"; fx=$((fx + 1)); }
@@ -197,6 +215,6 @@ rc=$?
# so output cut to its last lines still shows that there were findings to
# read; it is a pointer to the whole output, never its replacement.
st=; [ "$rc" -eq 0 ] || st="; content print exited $rc"
-printf 'end of scan — files: %s parsed: %s suspect: %s archive-suspect: %s principles: %s; finding lines above the entries (NOTE / LOST ENTRIES / GAP): %s%s. Read the output whole: never cut it with head, tail or grep\n' \
+printf 'end of scan — files: %s parsed: %s suspect: %s archive-suspect: %s principles: %s; finding lines above the entries (NOTE / LOST ENTRIES / UNFILLED / GAP): %s%s. Read the output whole: never cut it with head, tail or grep\n' \
"$n" "$parsed" "$suspect" "$a_sus" "$pr" "$fx" "$st"
exit "$rc"
diff --git a/scripts/validate-skill-bundle.py b/scripts/validate-skill-bundle.py
index 783bd7e..ef8689d 100644
--- a/scripts/validate-skill-bundle.py
+++ b/scripts/validate-skill-bundle.py
@@ -1159,6 +1159,10 @@ SCAN_FIXTURES = [
("previous scan 2 days old: no GAP line", "recent", True, 0, "files: 2", 2, "GAP:"),
("MOVED.md at the root: NOTE names it and its first line", "moved", True, 0,
'NOTE: pointer at this root (skill-observations/MOVED.md): "Moved to /new/root', 1, ""),
+ ("the helper's skeleton (empty title) is UNFILLED, not LOST", "skeleton", True, 0,
+ "UNFILLED — a header with an empty title", 1, "LOST ENTRIES —"),
+ ("id: below the filename prefix is named with its value", "idmis", True, 0,
+ "NOTE: id: does not read as the filename prefix", 1, ""),
]
@@ -1178,11 +1182,14 @@ def scan_case(scenario, pass_root):
day = datetime.date.today() - datetime.timedelta(days=21 if scenario == "gap" else 2)
ck.write_text(f"{day} 09:00 [w] session-start scan: files=2 parsed=2 principles=absent\n",
encoding="utf-8")
- if scenario != "broken":
- (log / "0001-a.md").write_text('---\nid: 1\ntitle: "ok"\n---\nbody\n', encoding="utf-8")
- (log / "0002-b.md").write_text("---\nid: 2\ntitle: Fix: unquoted\n---\n", encoding="utf-8")
- else:
+ if scenario == "broken":
(log / "0001-a.md").write_text('---\nid: 1\ntitle: "never closed"\n', encoding="utf-8")
+ else:
+ (log / "0001-a.md").write_text('---\nid: 1\ntitle: "ok"\n---\nbody\n', encoding="utf-8")
+ second = {"skeleton": '---\nid: 2\ntitle: ""\nstatus: open\nskill: []\n---\n',
+ "idmis": '---\nid: 1\ntitle: "retyped"\n---\n'}
+ (log / "0002-b.md").write_text(
+ second.get(scenario, "---\nid: 2\ntitle: Fix: unquoted\n---\n"), encoding="utf-8")
if scenario == "moved":
(root / "skill-observations" / "MOVED.md").write_text(
"Moved to /new/root on 2026-01-01\r\n", encoding="utf-8")