Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE/knowledge-sync.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

## Reviewer checklist

- [ ] The diff changes only the sidecar's copies, the site's copies, the `ktl` pin and its lock, and `CHANGELOG.md`.
- [ ] The diff changes only the sidecar's copies, the site's copies, the `ktl` pin and its lock, and the changelog.
- [ ] Any workflow changes held above are read and applied on this branch.
2 changes: 1 addition & 1 deletion .lokf/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ description = "LOKF knowledge-bundle tooling for collections."
# Keep in sync with the `lokf` toolkit's own requires-python floor.
requires-python = ">=3.11"
dependencies = [
"ktl==0.71.0",
"ktl==0.71.1",
"lokf[build]>=0.9.0",
# The recipe runner the workflows use, pinned here so uv.lock checks it
# by hash; keep the version in step with the workflows' uvx fallback.
Expand Down
107 changes: 79 additions & 28 deletions .lokf/scripts/knowledge-sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# - copies each template the host carries, adds one an `always` or `needs`
# line asks for, and lists the rest for ktl-sidecar's Step 5;
# - reports local edits it overwrote, and host files no manifest line names;
# - writes the changelog entry under "## [Unreleased]", "### Changed";
# - writes the changelog entry under "## [Unreleased]", "### Changed", in
# the changelog the host's site shows;
# - runs the sidecar's checks on the result.
# It starts from a clean tree, on the current branch or a new one from
# origin's default branch. It edits the pin line and runs `uv lock` because
Expand Down Expand Up @@ -184,25 +185,73 @@ add_entry() {
return 3
}

# The paths a sync may touch: the sidecar's and the site's copies, the pin,
# its lock and the changelog, in the plain characters the templates use.
sync_paths='^(\.github/workflows/knowledge-[a-z]+\.yaml|\.github/PULL_REQUEST_TEMPLATE/knowledge-[a-z]+\.md|\.lokf/scripts/knowledge-[a-z]+\.(sh|py)|\.lokf/m365/[A-Za-z0-9._-]+|\.lokf/(schema/)?domain\.yaml|\.lokf/\.gitattributes|\.lokf/\.gitignore|\.lokf/justfile|\.lokf/pyproject\.toml|\.lokf/uv\.lock|(ktl-)?website/.+|CHANGELOG\.md)$'
# The site's folder, the first of ktl-website/ and website/ that holds
# site.toml, as the website workflow picks it: <host>.
site_of() {
local o
for o in ktl-website website; do
if [[ -f "$1/$o/site.toml" ]]; then printf '%s\n' "$o"; return; fi
done
}

# The changelog the site shows, as a path from the host's root: <host>. It
# is CHANGELOG.md in the folder that site.toml's [params] source names, such
# as a fork's .linkml/, or else at the root. A line inside a multi-line
# string is not a key, as TOML reads it. A source outside the host, or not
# in plain characters, means the root.
changelog_of() {
local site src="" up='(^|/)\.\.?(/|$)' dotgit='(^|/)\.[Gg][Ii][Tt](/|$)'
site="$(site_of "$1")"
if [[ -n "$site" ]]; then
src="$(tr -d '\r' < "$1/$site/site.toml" | awk -v q="'" '
ml != "" { if (index($0, ml)) ml = ""; next }
/^[ \t]*#/ { next }
/^[ \t]*\[/ { t = $0; sub(/#.*/, "", t); gsub(/[ \t]/, "", t); in_params = (t == "[params]"); next }
!/=/ { next }
{
k = $0; sub(/=.*/, "", k); gsub(/[ \t]/, "", k); k = tolower(k)
v = $0; sub(/^[^=]*=[ \t]*/, "", v); c = substr(v, 1, 3)
}
in_params && (k == "source" || k == "\"source\"" || k == (q "source" q)) {
c = substr(v, 1, 1)
if (c == "\"" || c == q) {
r = substr(v, 2); e = index(r, c)
if (e > 0 && (c == q || index(substr(r, 1, e - 1), "\\") == 0)) print substr(r, 1, e - 1)
}
exit
}
(c == "\"\"\"" || c == (q q q)) && !index(substr(v, 4), c) { ml = c }')"
fi
src="${src#./}"; src="${src%/}"
if [[ -n "$src" && "$src" != "." && "$src" =~ $plain_path && "$src" != /* && ! "$src" =~ $up && ! "$src" =~ $dotgit ]]; then
printf '%s/CHANGELOG.md\n' "$src"
else
printf 'CHANGELOG.md\n'
fi
}

# The paths a sync may touch: the sidecar's and the site's copies, the pin
# and its lock, in the plain characters the templates use. The changelog is
# the one changelog_of names.
sync_paths='^(\.github/workflows/knowledge-[a-z]+\.yaml|\.github/PULL_REQUEST_TEMPLATE/knowledge-[a-z]+\.md|\.lokf/scripts/knowledge-[a-z]+\.(sh|py)|\.lokf/m365/[A-Za-z0-9._-]+|\.lokf/(schema/)?domain\.yaml|\.lokf/\.gitattributes|\.lokf/\.gitignore|\.lokf/justfile|\.lokf/pyproject\.toml|\.lokf/uv\.lock|(ktl-)?website/.+)$'
owned_paths='^(ktl-)?website/(site\.toml|README\.md|assets/css/custom\.css)$'
plain_path='^[]A-Za-z0-9._/@+[-]+$'

# --apply, for knowledge-sync.yaml's privileged job, which trusts nothing the
# patch's maker decided. The patch may edit and add plain files on the paths
# above, and move the pin line to <tag>'s version. `uv lock`, run here from
# the checkout's lock, must write the patch's lock, so its hashes are the
# index's (`uv lock --locked` does not compare hashes). A workflow pushed with
# a token runs on that push with the repository's secrets, so every workflow
# above and the changelog this checkout's own site.toml names, and move the
# pin line to <tag>'s version. `uv lock`, run here from the checkout's lock,
# must write the patch's lock, so its hashes are the index's
# (`uv lock --locked` does not compare hashes). A workflow pushed with a
# token runs on that push with the repository's secrets, so every workflow
# change goes to <held>, a patch a person applies on top.
apply_patch() {
local patch="$1" held="$2" tag="$3" paths wrong f full lane lines err
local patch="$1" held="$2" tag="$3" paths wrong f full lane lines err changelog
[[ -f "$patch" ]] || die "no such patch: $patch"
[[ -z "$(git status --porcelain)" ]] || die "the checkout has changes of its own; --apply takes a clean one"
paths="$(git -c core.quotePath=false apply --numstat -- "$patch" | cut -f3-)" || die "$patch is not a patch git can read"
wrong="$(printf '%s\n' "$paths" | grep -Ev "$sync_paths" || true)"
changelog="$(changelog_of .)"
wrong="$(printf '%s\n' "$paths" | grep -Ev "$sync_paths" | grep -vxF -- "$changelog" || true)"
wrong+=$'\n'"$(printf '%s\n' "$paths" | grep -E "$owned_paths" || true)"
wrong+=$'\n'"$(printf '%s\n' "$paths" | grep -Ev "$plain_path" || true)"
wrong+=$'\n'"$(printf '%s\n' "$paths" | grep -iE '(^|/)\.git(/|$)' || true)"
Expand Down Expand Up @@ -471,7 +520,8 @@ workflow_publish() {
local declined="${SYNC_DECLINED_PR:-}" lease="${SYNC_LEASE:-}"
local held="$RUNNER_TEMP/workflows.patch" heldmd="$RUNNER_TEMP/held.md" body="$RUNNER_TEMP/body.md"
local subject="chore(sidecar): sync copies and skills pin from $tag"
local bt='`' staged=1 link copies added url base
local bt='`' staged=1 link copies added url base changelog
changelog="$(changelog_of .)"
! git diff --cached --quiet || staged=0
: > "$heldmd"
if [[ -s "$held" ]]; then
Expand All @@ -494,7 +544,7 @@ workflow_publish() {
link="$repo_url/blob/$tag/CHANGELOG.md"
[[ -z "$from" || "$from" == "$tag" ]] || link="$repo_url/compare/$from...$tag"
# The copies are the staged files other than the changelog and the pin's.
copies="$(git -c core.quotePath=false diff --cached --name-status | awk -F'\t' -v p="$pyproject" -v l="$lock" '$1 == "M" && $2 != "CHANGELOG.md" && $2 != p && $2 != l { print $2 }')"
copies="$(git -c core.quotePath=false diff --cached --name-status | awk -F'\t' -v p="$pyproject" -v l="$lock" -v c="$changelog" '$1 == "M" && $2 != c && $2 != p && $2 != l { print $2 }')"
added="$(git -c core.quotePath=false diff --cached --name-status | awk -F'\t' '$1 == "A" { print $2 }')"
{
if [[ -n "$from" && "$from" != "$tag" ]]; then
Expand Down Expand Up @@ -527,10 +577,12 @@ workflow_publish() {
echo
echo "This repository's own checks run on this pull request, on the synced copies, with a read-only token. A failure there is a bundle to fix in this pull request, or the gate fails on it after the merge."
echo
if git diff --cached --quiet -- CHANGELOG.md; then
echo "CHANGELOG.md is unchanged: it has the entry already, or it has no Unreleased heading, in which case add the entry by hand."
if [[ ! -f "$changelog" ]]; then
echo "There is no $changelog here, so no entry was written."
elif git diff --cached --quiet -- "$changelog"; then
echo "$changelog is unchanged: it has the entry already, or it has no Unreleased heading, in which case add the entry by hand."
else
echo "CHANGELOG.md has the entry under its Unreleased heading and Changed."
echo "$changelog has the entry under its Unreleased heading and Changed."
fi
echo
if [[ -n "$declined" ]]; then
Expand Down Expand Up @@ -888,11 +940,9 @@ main() {
done

# The site: every template is synced, and a missing one added.
local website=0 site="" rel skip o new_w="$new_dir/$website_in" old_w=""
local website=0 site rel skip o new_w="$new_dir/$website_in" old_w=""
[[ -z "$old_dir" ]] || old_w="$old_dir/$website_in"
for o in website ktl-website; do
if [[ -z "$site" && -f "$host/$o/site.toml" ]]; then site="$o"; fi
done
site="$(site_of "$host")"
if [[ -n "$site" && -d "$new_w/website" ]]; then
website=1
while IFS= read -r rel; do
Expand Down Expand Up @@ -1001,7 +1051,7 @@ main() {
# The changelog entry, from what the sync did. The link compares the two
# pins. "No plugin change" is added for an Obsidian plugin, whose root
# manifest.json names minAppVersion.
local link tail="" entry list=() i changelog_line
local link tail="" entry list=() i changelog_line changelog
if [[ -n "$old_pin" && "$old_pin" != "$tag" ]]; then
link="$repo_url/compare/$old_pin...$tag"
else
Expand Down Expand Up @@ -1034,15 +1084,16 @@ main() {
for f in ${copied[@]+"${copied[@]}"} ${overwrote[@]+"${overwrote[@]}"}; do changed+=("$f"); done
for f in ${added[@]+"${added[@]}"}; do changed+=("${f%% (*}"); done
for f in ${lock_files[@]+"${lock_files[@]}"}; do changed+=("$f"); done
if [[ ! -f "$host/CHANGELOG.md" ]]; then
changelog_line="There is no CHANGELOG.md here, so no entry was written."
elif grep -qF "[$tag]($link)" "$host/CHANGELOG.md"; then
changelog_line="CHANGELOG.md already has the entry for $tag."
elif add_entry "$host/CHANGELOG.md" "$entry"; then
changelog_line="CHANGELOG.md has the entry, under its Unreleased heading and Changed."
changed+=("CHANGELOG.md")
changelog="$(changelog_of "$host")"
if [[ ! -f "$host/$changelog" ]]; then
changelog_line="There is no $changelog here, so no entry was written."
elif grep -qF "[$tag]($link)" "$host/$changelog"; then
changelog_line="$changelog already has the entry for $tag."
elif add_entry "$host/$changelog" "$entry"; then
changelog_line="$changelog has the entry, under its Unreleased heading and Changed."
changed+=("$changelog")
else
changelog_line="CHANGELOG.md has no Unreleased heading, so add the entry by hand:"$'\n'" $entry"
changelog_line="$changelog has no Unreleased heading, so add the entry by hand:"$'\n'" $entry"
fi
echo " entry $changelog_line"

Expand Down
10 changes: 5 additions & 5 deletions .lokf/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ The `v0.0.0` tag is a baseline, not a release: it marks where versioning starts

- **The shell lint runs the runner image's shellcheck instead of downloading one.**

### Changed

- **The sidecar copies and the skills pin are at Knowledge Trust Ladder [v0.71.1](https://github.com/noelmcloughlin/knowledge-trust-ladder/compare/v0.71.0...v0.71.1).** The release changed `.github/PULL_REQUEST_TEMPLATE/knowledge-sync.md`, `.lokf/scripts/knowledge-sync.sh`, `website/scripts/build.sh`, `website/scripts/prepare.sh` and `website/scripts/vendor.sh` here.

## [0.3.4] - 2026-11-30

### Fixed
Expand Down
10 changes: 5 additions & 5 deletions website/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
set -euo pipefail
here=$(cd "$(dirname "$0")/.." && pwd)
cd "$here"
mode=$(scripts/uv-env.sh "$here")
mode=$(bash scripts/uv-env.sh "$here")
tool=(uv run --project "$here" "$mode" --quiet)
# hugo.toml is the same on every site, and site.toml holds this repository's
# own values, read second so that they win.
Expand All @@ -30,7 +30,7 @@ if grep -qE '<(REPO|PROJ|SITE)_[A-Z]+>' site.toml; then
exit 1
fi

scripts/prepare.sh
bash scripts/prepare.sh
config=hugo.toml,site.toml
# The mounts of a source folder, which prepare.sh writes when site.toml names one.
[ -f generated/source.toml ] && config=$config,generated/source.toml
Expand All @@ -48,9 +48,9 @@ case "${1:-}" in
# The mark, new each build, sets off each page's raw HTML for clean-html.py.
mark=$("${tool[@]}" python -c 'import secrets; print(secrets.token_hex(12))')
HUGO_PARAMS_RAWMARK=$mark "${hugo[@]}" --gc --minify --cleanDestinationDir
"${tool[@]}" python scripts/clean-html.py dist "$mark"
"${tool[@]}" python -I scripts/clean-html.py dist "$mark"
"${tool[@]}" python -m pagefind --site dist
"${tool[@]}" python scripts/check-links.py dist "$("${hugo[@]}" config | sed -n 's/^baseurl = //p' | tr -d "\"'")"
"${tool[@]}" python -I scripts/check-links.py dist "$("${hugo[@]}" config | sed -n 's/^baseurl = //p' | tr -d "\"'")"
;;
serve)
# Pagefind indexes built pages, so one build gives the server an index.
Expand All @@ -63,7 +63,7 @@ case "${1:-}" in
preview)
mark=$("${tool[@]}" python -c 'import secrets; print(secrets.token_hex(12))')
HUGO_PARAMS_RAWMARK=$mark "${hugo[@]}" --gc --minify -d .preview --baseURL "http://localhost:$port/"
"${tool[@]}" python scripts/clean-html.py .preview "$mark"
"${tool[@]}" python -I scripts/clean-html.py .preview "$mark"
"${tool[@]}" python -m pagefind --site .preview
exec "${tool[@]}" python -m http.server "$port" --bind 127.0.0.1 --directory .preview
;;
Expand Down
4 changes: 2 additions & 2 deletions website/scripts/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ root=$(cd "$here/.." && pwd)
out="$here/generated"
# The site's own tools, as build.sh runs them, for the two checks below.
# uv-env.sh installs them, from a package mirror where uv reads one.
mode=$("$here/scripts/uv-env.sh" "$here")
mode=$(bash "$here/scripts/uv-env.sh" "$here")
tool=(uv run --project "$here" "$mode" --quiet)
# site.toml's values, read by a TOML parser as Hugo reads them, one
# `name=value` line each. A file the parser refuses stops the build here.
Expand Down Expand Up @@ -55,7 +55,7 @@ fi

# The bundle's own tools: lokf, and the LinkML it is built on, installed as
# the site's own are.
mode=$("$here/scripts/uv-env.sh" "$root/.lokf")
mode=$(bash "$here/scripts/uv-env.sh" "$root/.lokf")
lokf=(uv run --project "$root/.lokf" "$mode" --quiet)

# The domain vocabulary the sidecar's justfile names, so the export carries
Expand Down
2 changes: 1 addition & 1 deletion website/scripts/vendor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
set -euo pipefail
here=$(cd "$(dirname "$0")/.." && pwd)
command -v npm >/dev/null 2>&1 || { echo "vendor.sh: npm not found; it fetches each package from the registry it reads" >&2; exit 1; }
mode=$("$here/scripts/uv-env.sh" "$here")
mode=$(bash "$here/scripts/uv-env.sh" "$here")
# name, package@version, path in the package and SHA-256, one line each.
tool=(uv run --project "$here" "$mode" --quiet)
wanted=$("${tool[@]}" python -I - "$here/hugo.toml" "$@" <<'PY'
Expand Down
Loading