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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Sections dated before 2026-09-19 predate the cycle and stay as they are. Named m
`docs/RELEASE-PROCESS.md` §8.

## Unreleased
- fix(gate-check, status): **a `## Current stage` readout older than the newest `docs/BUILD-LOG.md` row is now named stale, and exec scripts run since Stage 5 with no `cr:` tag and no build-plan row are listed under the `Change log:` line (#767)** — both warn-only and computed when read (one awk over the log per gate-check/status run, nothing per exec row; `exec.sh` untouched): gate-check (every run) and `status.sh` (WATCH) print `Current stage line is from <date>; N exec rows since — re-run bin/gate-check.sh`; gate-check's rewrite now stamps `· last exec <date>` inside the parenthesis (the `**Stage N` prefix that `status.sh`, `token-burn.sh` and `obligation-check.sh` parse is unchanged) and also rewrites when that date moved; the nudge reads Stage 5's start as the first exec row the plan names (verbatim or `060-…-x.mdl`) and never changes the Change log verdict or an exit code. New `bin/lib/build-log-read.sh`; fixtures `test-stage-header.sh` T13, `test-change-log.sh` T10 — field report, greenfield build in auto mode, 2026-11-13
- fix(platform-link): **going live, the toolkit project IS the Team Server copy (#765)**: an app built with the toolkit went live through a separate Team Server working copy with no `.mxtk`, so every later change skipped the exec gate, snapshots and BUILD-LOG, and nothing said so. `skills/platform-link.md` §3 now states the rule and adds a six-step recovery for a copy that already split off (fetch it in, take its model whole, `mxcli fix hashes` + gate, adopt with `-X ours` and push without force, sync the metadata notes, retire the extra copy; the `mprname` trap, ContentsHash after a checkout, and the model-aware merge path needing mxcli ≥ 0.30); one-line pointers from the runbook's Stage 6 and `deploy-to-sandbox.md`. `bin/status.sh` WATCHes, local git only and exit code unchanged, at Stage 6+ when no remote URL names Team Server, and when a fetched Team Server ref is in no local branch ("Team Server has commits made outside the toolkit"). New `tests/wave2/test-status-teamserver.sh` — greenfield field run, 2026-11-13
- fix(marketplace-check, portability): **`bin/exec.sh` on a domain-model script no longer stops at the marketplace check on macOS `/bin/bash` 3.2 (#763)**: `_mkt_locate` ran `case "$m" in *"refusing to guess"*) ...` inside `$( ... )`, and bash 3.2 read the pattern's `)` as the end of the substitution (the #552 class, `bash -n` blind to it). The pattern now uses the POSIX leading paren `(pat)`; a sweep of `bin/`, `bin/lib/`, `project-bin/` and `claude-hooks/` found no other. New `bin/check-portability.sh` rule 3 (`bin/lib/case-in-subst.awk`, multi-line) flags a case pattern without a leading `(` inside `$( )`, so a third one cannot land; fixture `tests/wave2/test-case-in-subst.sh` — thanarat
- fix(intake,interview-protocol): **the intake preamble and `interview-protocol.md` now state the Stage P answer form for `Interview mode: auto`, `Assumed (auto-mode): <default> — rejected: <alt>`, colon right after the parenthesis (#766)**: the preamble listed only `Answered (CONFIRMED):` and `Unverified — how to verify:`, and the protocol said "recorded `ASSUMED` as above", pointing at the register shape the intake gate rejects, so an auto-mode kickoff learned the accepted form only from the FAIL message. Text only: the gate matcher and Q9 are unchanged, and existing intakes are not re-synced. Proof: `tests/wave2/test-stage-p.sh` T12 (fails on master's template) — field report from a greenfield auto-mode build, relayed by the maintainer
Expand Down
37 changes: 35 additions & 2 deletions bin/gate-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3153,6 +3153,11 @@ fi
# more correct for projects that keep their build log elsewhere, and is the obvious follow-up;
# it is not done here because a missing/renamed log must never be the reason an ack fails.
BUILD_LOG="$PROJECT_DIR/docs/BUILD-LOG.md"
# Read-time checks over that log (#767): the stale-readout note and the unlogged-ask nudge.
if [ -r "$TOOLKIT_DIR/bin/lib/build-log-read.sh" ]; then
# shellcheck source=lib/build-log-read.sh
. "$TOOLKIT_DIR/bin/lib/build-log-read.sh"
fi
build_log_append() {
mkdir -p "$(dirname "$BUILD_LOG")" 2>/dev/null || true
printf '%s %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$1" >> "$BUILD_LOG"
Expand Down Expand Up @@ -3527,6 +3532,14 @@ else
fi
fi
fi
# Unlogged asks (#767): exec scripts run since Stage 5 started that carry no `cr:` tag and that the
# build plan does not name — the asks that went straight into MDL, which the counts above cannot
# see (0 rows reads PASS). A separate warn line under "Change log:", never a verdict change.
CR_UNLOGGED=""
if command -v mxtk_unlogged_execs >/dev/null 2>&1; then
_cr_plan="$(resolve_artifact "architecture/build-plan.md" || true)"
[ -n "$_cr_plan" ] && CR_UNLOGGED="$(mxtk_unlogged_execs "$BUILD_LOG" "$_cr_plan")"
fi
# ---------------------------------------------------------------------------
# Read for this gate — the runbook lines this stage actually needs.
#
Expand Down Expand Up @@ -3604,6 +3617,12 @@ if [ -n "$CR_ROWS" ]; then
_cr_more=$(( $(printf '%s\n' "$CR_ROWS" | grep -c .) - 10 ))
[ "$_cr_more" -gt 0 ] && echo " … and $_cr_more more in the register"
fi
if [ -n "$CR_UNLOGGED" ]; then
_cr_un_n="$(printf '%s\n' "$CR_UNLOGGED" | grep -c .)"
echo " WARN — $_cr_un_n exec script(s) since Stage 5 started with no cr: tag and no build-plan row (an unlogged ask? log it in ## Change log, then exec --cr CR-NN — skills/change-intake.md) — warn-only:"
printf '%s\n' "$CR_UNLOGGED" | head -n 10 | sed 's/^/ /'
[ "$_cr_un_n" -gt 10 ] && echo " … and $((_cr_un_n - 10)) more in docs/BUILD-LOG.md"
fi

# ---------------------------------------------------------------------------
# Open questions — has the project actually ASKED what it wrote down?
Expand Down Expand Up @@ -4374,7 +4393,13 @@ if { [ "$WRITE_HTML" = "1" ] || [ "$_single_query" = "1" ]; } && [ -n "$REGISTER
fi
_line="$_line — gates passed: ${_passed:-none yet}"
[ -n "$_manual" ] && _line="$_line · manual: $_manual"
_stamp=" (derived by gate-check on $(date -u +%Y-%m-%d); re-run it rather than editing this line)."
# "· last exec <date>" (#767): the newest docs/BUILD-LOG.md row this readout saw. Read back by
# mxtk_stage_stale_note below and in status.sh, so a build that keeps exec-ing after its last
# gate-check run is told its readout is stale. Inside the parenthesis on purpose: status.sh,
# token-burn.sh and obligation-check.sh parse only the "**Stage N" prefix.
_last_exec=""
command -v mxtk_build_log_last_date >/dev/null 2>&1 && _last_exec="$(mxtk_build_log_last_date "$BUILD_LOG")"
_stamp=" (derived by gate-check on $(date -u +%Y-%m-%d)${_last_exec:+ · last exec $_last_exec}; re-run it rather than editing this line)."
# Rewrite only when the position moved — a new date alone is not a change worth a diff — and
# ONLY over a line nobody wrote by hand: the untouched scaffold line, or this readout's own
# earlier line. A human's line is never replaced (field run 2026-09-14, twelve real projects:
Expand Down Expand Up @@ -4402,7 +4427,8 @@ if { [ "$WRITE_HTML" = "1" ] || [ "$_single_query" = "1" ]; } && [ -n "$REGISTER
echo ""
echo "Current stage in $(basename "$REGISTER") is hand-written and left alone: $(printf '%s' "$_have" | cut -c1-70)"
echo " gates derive: $(printf '%s' "$_line" | sed 's/\*\*//g')"
elif [ "${_have%% (derived by gate-check*}" != "$_line" ]; then
elif [ "${_have%% (derived by gate-check*}" != "$_line" ] \
|| [ "$(printf '%s' "$_have" | sed -nE 's/.*· last exec ([0-9-]+).*/\1/p')" != "$_last_exec" ]; then
_tmp="$(mktemp "${TMPDIR:-/tmp}/curstage.XXXXXX")"
if MXTK_CUR_LINE="$_line$_stamp" awk '
/^## Current stage/ { print; insec = 1; next }
Expand All @@ -4419,6 +4445,13 @@ if { [ "$WRITE_HTML" = "1" ] || [ "$_single_query" = "1" ]; } && [ -n "$REGISTER
fi
fi
fi
# Stale readout (#767) — on EVERY run, after any rewrite above (so a full run that just refreshed
# the line says nothing). Warn-only: a stage query, a blocked run or a --no-html run keeps the old
# line and is told so; nothing refuses on it.
if [ -n "$REGISTER" ] && [ -f "$REGISTER" ] && command -v mxtk_stage_stale_note >/dev/null 2>&1; then
_stale_note="$(mxtk_stage_stale_note "$REGISTER" "$BUILD_LOG")"
[ -n "$_stale_note" ] && { echo ""; echo "WARN: $_stale_note"; }
fi

# ---------------------------------------------------------------------------
# --closeout — emit the block and stop. Placed AFTER every evaluation (the verdict line must
Expand Down
94 changes: 94 additions & 0 deletions bin/lib/build-log-read.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/env bash
# Read-time checks over docs/BUILD-LOG.md (issue #767) — ONE copy, sourced by bin/gate-check.sh
# and bin/status.sh. Nothing here runs per exec row: project-bin/exec.sh is not touched, and both
# checks cost one awk over the log, only when a person or agent READS the position.
#
# WHY (field report, 2026-11-13, a greenfield build in auto mode). 1) The build finished and
# PROJECT.md still said "Stage P — needs attention": "## Current stage" is written only by a
# gate-check run, nobody re-ran it after the last exec, and nothing compared the readout's
# stamp with the exec rows written after it. 2) Late asks ("add an admin account") went
# straight into a numbered script with no change-intake row, so the change log stayed empty and
# its gate line read PASS on 0 rows.
#
# PRODUCER for the consumer (CLAUDE.md "Shipping an instrument" rule 5): the BUILD-LOG rows are
# written by project-bin/exec.sh log_build() on every exec (the mandatory build step); the stamp
# by gate-check.sh's own "## Current stage" rewrite; the plan by Stage 4 (architecture/build-plan.md).
#
# WARN-ONLY. Neither function changes a verdict or an exit code.
#
# Sourced, never executed. Side-effect free.

# mxtk_build_log_last_date <build-log> → the date (YYYY-MM-DD) of the newest exec row, or nothing.
# Exec rows are the table rows exec.sh writes: `| 2026-10-21T05:41:52+0000 | `x.mdl` | … |`.
# gate-check's own ack/bypass lines (`2026-…Z PROTOCOL-BYPASS`) are not table rows, not counted.
mxtk_build_log_last_date() {
[ -f "${1:-}" ] || return 0
awk '/^\| *[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/ {
s = $0; sub(/^\| */, "", s); d = substr(s, 1, 10); if (d > m) m = d }
END { if (m != "") print m }' "$1" 2>/dev/null
}

# mxtk_stage_stale_note <register> <build-log> → one line, or nothing.
# "Current stage line is from <date>; N exec rows since — re-run bin/gate-check.sh"
# Only for gate-check's own derived line (a hand-written line has no stamp to be stale against).
# The reference date is the stamp's "· last exec <date>" when present — a date the log itself
# wrote, so no UTC-vs-local skew — else the "derived by gate-check on <date>" date (lines written
# before #767). Day granularity: rows on the reference day itself are not counted, which can miss
# a same-day exec but never warns on a readout that is current.
mxtk_stage_stale_note() {
local reg="${1:-}" log="${2:-}" line derived ref n
[ -f "$reg" ] && [ -f "$log" ] || return 0
line="$(awk '/^## Current stage/{f=1;next} f && /^## /{exit} f && /^\*\*/{print;exit}' "$reg" 2>/dev/null | tr -d '\r')"
case "$line" in *"(derived by gate-check on "*) ;; *) return 0 ;; esac
derived="$(printf '%s' "$line" | sed -nE 's/.*\(derived by gate-check on ([0-9]{4}-[0-9]{2}-[0-9]{2}).*/\1/p')"
ref="$(printf '%s' "$line" | sed -nE 's/.*· last exec ([0-9]{4}-[0-9]{2}-[0-9]{2}).*/\1/p')"
[ -n "$ref" ] || ref="$derived"
[ -n "$ref" ] || return 0
n="$(MXTK_REF="$ref" awk '/^\| *[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/ {
s = $0; sub(/^\| */, "", s); if (substr(s, 1, 10) > ENVIRON["MXTK_REF"]) n++ }
END { print n + 0 }' "$log" 2>/dev/null)"
[ "${n:-0}" -gt 0 ] 2>/dev/null || return 0
printf 'Current stage line is from %s; %s exec rows since — re-run bin/gate-check.sh\n' "${derived:-$ref}" "$n"
}

# mxtk_unlogged_execs <build-log> <build-plan> → one script name per line (first-seen order,
# deduplicated), or nothing.
# A script run after Stage 5 started that carries no `cr:` tag in its detail cell and that the
# build plan does not name is an ask nobody logged (skills/change-intake.md).
# "Stage 5 started" = the first exec row whose script the plan names: the BUILD-LOG is what was
# built, and the stage readout is the very thing #767 found stale. A log where no row matches the
# plan prints nothing — the plan may name scripts in a shape this cannot read, and flagging every
# row would be noise, not a nudge.
# Plan matching: the basename verbatim, or the plan's abbreviated form
# "060-…-customer_overview.mdl" (brd-to-build-plan.md) — prefix before the ellipsis, suffix after.
mxtk_unlogged_execs() {
local log="${1:-}" plan="${2:-}"
[ -f "$log" ] && [ -f "$plan" ] || return 0
awk '
FNR == NR {
plan = plan "\n" $0
line = $0
while (match(line, /[A-Za-z0-9_.-]*(…|\.\.\.)[A-Za-z0-9_.-]*\.(mdl|py)/)) {
tok = substr(line, RSTART, RLENGTH); line = substr(line, RSTART + RLENGTH)
e = index(tok, "…"); el = length("…")
if (e == 0) { e = index(tok, "..."); el = 3 }
npre++; pre[npre] = substr(tok, 1, e - 1); suf[npre] = substr(tok, e + el)
}
next
}
/^\| *[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/ {
n = split($0, c, "|"); if (n < 6) next
name = c[3]; gsub(/[` \t]/, "", name); sub(/^patch:/, "", name)
if (name == "") next
inplan = (index(plan, name) > 0)
for (i = 1; !inplan && i <= npre; i++)
if (length(name) >= length(pre[i]) + length(suf[i]) \
&& substr(name, 1, length(pre[i])) == pre[i] \
&& substr(name, length(name) - length(suf[i]) + 1) == suf[i]) inplan = 1
if (inplan) { started = 1; next }
if (!started) next
if ($0 ~ /cr: *CR-[0-9]/) next
if (!(name in seen)) { seen[name] = 1; print name }
}
' "$plan" "$log" 2>/dev/null
}
6 changes: 5 additions & 1 deletion bin/status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ esac
# --- register facts -------------------------------------------------------------------------
STAGE_LINE="$(awk '/^## Current stage/{f=1;next} f && /^\*\*Stage/{print;exit}' "$REG" | sed -E 's/\*\*//g; s/,? *(in progress)?\.?$//')"
[ -n "$STAGE_LINE" ] || STAGE_LINE="(no Current stage line in PROJECT.md)"
# The readout is only as fresh as the last gate-check run that wrote it (#767): one awk over
# docs/BUILD-LOG.md says when exec rows landed after it. Warn-only, shown under WATCH.
. "$TOOLKIT_ROOT/bin/lib/build-log-read.sh"
STAGE_STALE="$(mxtk_stage_stale_note "$REG" "$PROJECT_DIR/docs/BUILD-LOG.md")"
ENTRY_RAW="$(awk '
{ line = $0
gsub(/^[ \t>*_-]+/, "", line)
Expand Down Expand Up @@ -337,7 +341,7 @@ esac
TK="toolkit $TK_COMMIT_NOW"; [ -n "$TK_COMMIT_REG" ] && [ "$TK_COMMIT_REG" != "$TK_COMMIT_NOW" ] && TK="$TK (register says $TK_COMMIT_REG)"
[ -n "$TK_UPD" ] && TK="$TK · updates: $TK_UPD"
WATCH=""
for _w in "${APPROVED_OVER:+APPROVED OVER A FAILING GATE: $APPROVED_OVER}" "$DONE_STALL" "${BP_STALE%% (*}" \
for _w in "$STAGE_STALE" "${APPROVED_OVER:+APPROVED OVER A FAILING GATE: $APPROVED_OVER}" "$DONE_STALL" "${BP_STALE%% (*}" \
"$( [ "${PH_TOTAL:-0}" -gt 0 ] && [ "$EAC" = 0 ] && echo "agent slots unfilled: $PH_TOTAL in $PH_FILES file(s)" )" "$PACK_GAP" "$LINT_UNVERSIONED" "$TS_WATCH"; do
[ -n "$_w" ] && WATCH="${WATCH:+$WATCH · }$_w"
done
Expand Down
42 changes: 42 additions & 0 deletions tests/wave2/test-change-log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,48 @@ OUT="$("$SYNC" "$P9" 2>&1)"
printf '%s\n' "$OUT" | grep -q "appended the '## Change log' section" && bad "sync claims it appended a section to a CRLF file that has one" \
|| ok "sync does not append to a CRLF file"

echo "== T10 (issue #767): an exec script since Stage 5 with no cr: and no build-plan row is listed, warn-only =="
# GOLDEN INPUT: every BUILD-LOG row is the verbatim exec.sh capture in fixtures/verify-446, with
# only its timestamp, script name and (for one row) the cr tag exec.sh appends substituted.
CAP="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/fixtures/verify-446/BUILD-LOG.captured.md"
ROW="$(grep -m1 '^| 2026-' "$CAP")"
row() { # row <time> <script> [cr] — the captured row with three cells substituted
local r="${ROW/2026-10-21T05:41:52/$1}"; r="${r/\`test.mdl\`/\`$2\`}"
[ -n "${3:-}" ] && r="${r/ · change: logic/ · change: logic · cr: $3}"
printf '%s\n' "$r"
}
P10="$(mkproj t10)"; mkdir -p "$P10/docs" "$P10/architecture"
cat > "$P10/architecture/build-plan.md" <<'EOF3'
# Build plan

| # | Kind | Step | What | Depends on |
|---|---|---|---|---|
| 10 | BUILD | 010-crm-domain.mdl | CRM domain model | |
| 21 | BUILD | UC-F002-01 Browse customers: 020-…-customer_overview.mdl | Customer list | 10 |
EOF3
{ sed -n '1,/^|---/p' "$CAP"
row 2026-10-20T09:00:00 001-scaffold.mdl # before Stage 5: not listed
row 2026-10-21T09:00:00 010-crm-domain.mdl # in the plan: Stage 5 starts here
row 2026-10-21T10:00:00 020-crm-page-customer_overview.mdl # matches the abbreviated plan row
row 2026-10-22T09:00:00 070-admin-account.mdl # the unlogged ask
row 2026-10-22T10:00:00 071-vat-number.mdl CR-01 # logged: cr tag
row 2026-10-22T11:00:00 070-admin-account.mdl # re-run: listed once
} > "$P10/docs/BUILD-LOG.md"
[ "$(grep -c '^| 2026-' "$P10/docs/BUILD-LOG.md")" = "6" ] && ok "precondition: 6 captured-shape rows" || bad "row build failed"
OUT10="$("$GATE" --no-html "$P10" 2>&1)"; RC10=$?
BLK="$(printf '%s\n' "$OUT10" | sed -n '/^Change log:/,/^[^ ]/p')"
printf '%s\n' "$BLK" | grep -q "WARN — 1 exec script(s) since Stage 5 started with no cr: tag and no build-plan row" \
&& ok "nudge line under Change log: names 1 script" || bad "no nudge line" "$BLK"
printf '%s\n' "$BLK" | grep -qx ' 070-admin-account.mdl' && ok "070-admin-account.mdl listed" || bad "unlogged script not listed" "$BLK"
for s in 001-scaffold.mdl 010-crm-domain.mdl 020-crm-page-customer_overview.mdl 071-vat-number.mdl; do
printf '%s\n' "$BLK" | grep -q "^ $s" && bad "$s listed" "$BLK" || ok "$s not listed"
done
[ "$(printf '%s\n' "$BLK" | grep -c '^ 070-admin-account.mdl')" = "1" ] && ok "re-run listed once" || bad "duplicate listing" "$BLK"
printf '%s\n' "$OUT10" | grep -q '^Change log: PASS — 0 change requests logged' && ok "verdict unchanged: still PASS (warn line is separate)" \
|| bad "Change log verdict changed" "$(printf '%s\n' "$OUT10" | grep '^Change log:')"
rm -f "$P10/docs/BUILD-LOG.md"; "$GATE" --no-html "$P10" >/dev/null 2>&1; RC10b=$?
[ "$RC10" = "$RC10b" ] && ok "exit $RC10 with the unlogged row = $RC10b without" || bad "exit differs: $RC10 vs $RC10b"

echo ""
echo "test-change-log: $PASS passed, $FAIL failed"
[ "$FAIL" -eq 0 ]
Loading
Loading