From 323baebb456a4fb7e23eae2dd377729d51dff9de Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 10:45:38 +0700 Subject: [PATCH 01/19] feat(wrap): one-call gather with live named PRs and a needs-you check wrap session gains three gather flags so /kit:wrap runs one gather call: - --prs owner/name#n,... reads every PR the transcript names in one batched GraphQL call (state, merged, mergedAt, merge commit, head branch), so the report never states a cached PR state. - --summary prints the gather as one fact per line, so the command never re-reads the JSON with jq. --text on the gather means the same. - --mark-dir folds step 0's per-repo writer check and mark into the gather. commands/wrap.md now runs one session recall --replies digest, one gather, then the report; it names the calls the gather replaces, finds handed-off PRs with one live search, re-gathers only after a write, and walks the digest for owner actions before Needs you may say NOTHING. ## How I verified it bash tests/test-wrap-session.sh -> test-wrap-session: all 122 passed Negative control: the new cases on master's wrap-session.sh -> 11 passed, 44 FAILED of 55 --- commands/wrap.md | 23 ++--- lib/wrap/wrap-session.sh | 175 +++++++++++++++++++++++++++++++++++-- tests/test-wrap-session.sh | 139 ++++++++++++++++++++++++++++- 3 files changed, 318 insertions(+), 19 deletions(-) diff --git a/commands/wrap.md b/commands/wrap.md index 41380e7a..34abbd86 100644 --- a/commands/wrap.md +++ b/commands/wrap.md @@ -12,26 +12,25 @@ Run after `/kit:ship`, at session end, or when the operator asks to land work. N The distill half is the candidate scan, both seams, steps 7a-7c, and the drain. It is on unless the operator root config sets `wrap.distill = false`; `harvest` hands it to the harvest sweep only when `/sweep/installed` exists and `harvest.enable` is true. With distill off, skip those distill steps by name and report `SKIPPED: distill off`. The retro is landing, not distill, and still runs when its ledger condition is met. Harvest mode reports `SKIPPED: distill runs in the harvest sweep`; in phase 1 the sweep reports candidates and builds none. Read `harvest_sweep.py --status` for the newest report. When the knob resolves as true but the marker is absent, the FYI row says `not installed on this host`. An explicit one-shot distill means the sweep will also see this session. -**Wrapping another session.** Never scan the wrapper's empty context. Resolve it with `bin/session recall --name`, list worker transcripts with `bin/session recall --subagents`, confirm the target with `bin/session recall --tail ` and check its hint against `git` or `gh`, collect the target and pickup transcript paths, dispatch one read-only Sonnet miner, and use only its candidate list and landing facts. The lead never reads a transcript into its own context. +**Wrapping another session.** Never scan the wrapper's empty context. Use the transcript path the operator or the dispatch gives; when you have only a name, resolve it with `bin/session recall --name`. Then make ONE digest call: `bin/session recall --replies `, every turn's prompt and final reply. That digest is the only transcript read. It names the repos, the PRs, the board rows, and the operator's open asks. Only when the digest cannot name the landing facts (a turn ended with no final reply), list worker transcripts with `bin/session recall --subagents` and dispatch one read-only Sonnet miner; use only its candidate list and landing facts. The lead never reads a transcript into its own context. ## Start gather -Bracket timing: `bash lib/gate/gate-ledger.sh outcome wrap start`. Resolve each main checkout once from a worktree with `git -C rev-parse --path-format=absolute --git-common-dir` minus `/.git`. Before the gather reads a repo, pass one `--self` for every worktree the target session owns: its EnterWorktree, every `agent-*` subagent worktree, and every `wrap start` worktree. Record the writer mark then, under a slash-free repo key: +Bracket timing: `bash lib/gate/gate-ledger.sh outcome wrap start`. Resolve each main checkout once from a worktree with `git -C rev-parse --path-format=absolute --git-common-dir` minus `/.git`. Pass one `--self` for every worktree the target session owns: its EnterWorktree, every `agent-*` subagent worktree, and every `wrap start` worktree. Pass every PR the digest names, own or not, in `--prs`. Then run the whole gather as ONE call: ```bash -writers_mark="$scratch/writers-.json" -bin/wrap session --writers --since --mark "$writers_mark" [--self ]... +bin/wrap session --summary --prs ,... --mark-dir "$scratch" --since [--self ]... [--follow-mode lanes|all] ... ``` -This first run is step 0's check for activity before the wrap: its `foreign_activity` (an `index.lock`, or a reflog row newer than the session start in any worktree except the session's own, the main checkout included) stops the repo exactly as the landing pass describes. Use the target session's real start epoch; without one, use the time this wrap started. +- `--prs` reads every named PR live, in one batched GitHub call: state, merged, mergedAt, merge commit, head branch. A PR's state in the report comes from this read, never from the transcript. +- `--mark-dir` is step 0's check for activity before the wrap, taken per repo before the repo is read. It records each writer mark as `writers_mark="$scratch/writers-.json"`, the repo's absolute path without its leading slash and with `/` as `-`; the `writers` line prints the path. Its `foreign_activity` (an `index.lock`, or a reflog row newer than the session start in any worktree except the session's own, the main checkout included) stops the repo exactly as the landing pass describes. Use the target session's real start epoch; without one, use the time this wrap started. +- `--summary` prints every field this command reads, one fact per line. Read it once. `--json` prints the same gather as one `wrap-session/1` document for a tool; never re-read either with `jq`. -Then run the start gather, saving the JSON: +The gather holds config knobs, activity-log state, the named PRs, and per repo the checkout, dirty files, worktrees, writer facts, active board rows, handoffs, own open PRs with check totals and gates, recent merge deploy state, and the sweep report. Treat it as facts, not as proof of intent. Rows this session did not touch stay untouched. -```bash -bin/wrap session --json [--follow-mode lanes|all] ... > "$scratch/session.json" -``` +**What the gather replaces.** Run none of these when the gather covers the fact: `git status`, `git for-each-ref` or any other git ref read; `wrap scan`; a grep, `rg`, `jq` or Read over the transcript; a re-read of the gather; `gh pr view` one PR at a time (put the PR in `--prs`). The target is 10 lead calls per wrap: this file, the digest, the gather, the step 7b lookups, `flick-7b`, and only the writes a decision needs. -The document is `wrap-session/1`: config knobs, activity-log state, and per repo the checkout, dirty files, worktrees, reflog and index-lock facts, active board rows, handoffs, own open PRs with check totals and gates, recent merge deploy state, and the sweep report. Treat it as facts, not as proof of intent. Rows this session did not touch stay untouched. Save the target session's real start epoch when known; otherwise `.generated_at_epoch` is the fallback writer-check threshold when no mark exists. +**Handed-off work.** A change the session handed to another agent or bot ("X will open the PR") has no ref in the digest. Find it with one `gh pr list --repo --state all --search ""` and state only what that live read shows. Never call a PR or a handed-off change pending, open, or merged from the transcript alone. `config` carries the root-only values of `wrap.distill`, `wrap.before`, `wrap.after`, `wrap.merge_own_prs`, `wrap.tidy_worktrees`, `wrap.delete_merged_remote_branches`, `wrap.carry_stray_lines`, `wrap.autoland_carry`, `wrap.build_candidates`, `kit_config_get_root wrap.build_lanes`, `wrap.drain_staged`, and the mode that `bin/wrap follow-mode [lanes|all]` resolves. Every false knob turns its write into a report line and earns a `STATE` row. @@ -78,7 +77,9 @@ The after seam invokes the configured `wrap.after` skill after landing. Empty is ## Report -Before drafting, run one final read-only gather over the same repos: `bin/wrap session --json ... > "$scratch/session-final.json"`. `Left alone` uses that final gather, never memory or the start snapshot. Draft the skim-first report, write it to scratch. Run the lint before printing: `bash lib/wrap/report-lint.sh `. Fix or do what the lint names, then re-run. The shape is: +When any write step ran, run one final read-only gather over the same repos before drafting: `bin/wrap session --summary ...`. `Left alone` uses that final gather, never memory or the start snapshot. When no write ran (a dry run, or nothing to land), the start gather is the final state; do not gather again. + +**Needs-you check, before writing `NOTHING`.** Walk the digest's replies, newest first, and list every owner action they name: an ask to the operator, a blocker, a lettered `a.` `b.` item, "needs Han" or "needs you", an approval, and a merge, close, or click left to the owner. Each one is either proven done by a gather row or a live read, or it goes under `Needs you`. When unsure, list it with `check`: `a. RUN check . .` Write `NOTHING` only when this walk found no open item, never because the gather shows nothing. Draft the skim-first report, write it to scratch. Run the lint before printing: `bash lib/wrap/report-lint.sh `. Fix or do what the lint names, then re-run. The shape is: ```markdown ## Wrap: diff --git a/lib/wrap/wrap-session.sh b/lib/wrap/wrap-session.sh index 3da8feb9..0d24ffba 100644 --- a/lib/wrap/wrap-session.sh +++ b/lib/wrap/wrap-session.sh @@ -557,6 +557,111 @@ _session_config_json() { build_lanes:$build_lanes,drain_staged:$drain_staged,follow_mode:$follow_mode,follow_lanes:$follow_lanes}}' } +# _session_pr_refs ... -- every PR ref as `owner/name#n`, one per line, deduplicated. +# Accepts `owner/name#n` and `https://github.com/owner/name/pull/n`, comma or space separated. +# A ref that matches neither shape is an error: it never reaches the GraphQL query text. +_session_pr_refs() { + local word ref owner name n + for word in "$@"; do + for ref in $(printf '%s' "$word" | tr ',' ' '); do + case "$ref" in + https://github.com/*/pull/*) ref="${ref#https://github.com/}"; n="${ref##*/pull/}"; n="${n%%[/?#]*}"; ref="${ref%%/pull/*}#$n" ;; + esac + owner="${ref%%/*}"; name="${ref#*/}"; name="${name%%#*}"; n="${ref##*#}" + if ! printf '%s' "$ref" | grep -Eq '^[A-Za-z0-9][A-Za-z0-9-]*/[A-Za-z0-9_.-]+#[0-9]+$'; then + echo "wrap.sh session --prs: '$ref' is not owner/name#n" >&2; return 64 + fi + printf '%s/%s#%s\n' "$owner" "$name" "$n" + done + done | awk '!seen[$0]++' +} + +# _session_named_prs_json -- every named PR read live in ONE batched GraphQL call, +# so the report never states a PR state cached in a transcript. A ref GitHub cannot resolve +# stays a row with its error; no ref is dropped. +_session_named_prs_json() { + local refs="$1" ghs query out rows now + now="$(date -u +%Y-%m-%dT%H:%M:%SZ)" + ghs="$(_gh_state)" + if [ "$ghs" != "ok" ]; then + rows="$(printf '%s\n' "$refs" | jq -R --arg e "gh $ghs" 'select(length > 0) | {ref:., error:$e}' | jq -s .)" + jq -cn --arg state "$ghs" --arg now "$now" --argjson rows "$rows" '{gh_state:$state,read_at:$now,error:"gh \($state)",rows:$rows}' + return 0 + fi + # One alias per repo (r) and per PR (p); refs are validated, so the text is safe to inline. + query="$(printf '%s\n' "$refs" | awk -F'[/#]' 'NF == 3 { + key = $1 "/" $2 + if (!(key in idx)) { idx[key] = n++; order[idx[key]] = key } + prs[idx[key]] = prs[idx[key]] sprintf(" p%s: pullRequest(number: %s) { ...F }", $3, $3) + } + END { + printf "query {" + for (i = 0; i < n; i++) { split(order[i], on, "/"); printf " r%d: repository(owner: \"%s\", name: \"%s\") {%s }", i, on[1], on[2], prs[i] } + printf " } fragment F on PullRequest { number title url state merged mergedAt mergeCommit { oid } headRefName baseRefName isDraft author { login } }\n" + }')" + # gh exits non-zero on a partial GraphQL error but still prints the data, so stdout is read either way. + out="$(gh api graphql -f query="$query" 2>/dev/null)" + printf '%s' "$out" | jq -e 'type == "object"' >/dev/null 2>&1 || out='{}' + rows="$(printf '%s\n' "$refs" | awk -F'[/#]' 'NF == 3 { + key = $1 "/" $2 + if (!(key in idx)) idx[key] = n++ + printf "%s\tr%d\tp%s\n", $0, idx[key], $3 + }' | jq -R --argjson doc "$out" ' + split("\t") as [$ref, $r, $p] + | ($doc.data[$r][$p] // null) as $pr + | if $pr == null then + {ref:$ref, error:(([$doc.errors[]? | select((.path // []) | index($r)) | .message] | first) + // (if ($doc.data // null) == null then "graphql read failed" else "not found" end))} + else + {ref:$ref, number:$pr.number, title:$pr.title, url:$pr.url, state:$pr.state, merged:$pr.merged, + merged_at:$pr.mergedAt, merge_sha:($pr.mergeCommit.oid // null), head_branch:$pr.headRefName, + base_branch:$pr.baseRefName, draft:$pr.isDraft, author:($pr.author.login // null), error:null} + end' | jq -s .)" + [ -n "$rows" ] || rows='[]' + jq -cn --arg now "$now" --argjson rows "$rows" '{gh_state:"ok",read_at:$now,error:null,rows:$rows}' +} + +# _session_summary_text -- the compact view of one wrap-session/1 document: every field +# commands/wrap.md reads, one fact per line, so the report never re-reads the JSON. +_session_summary_text() { + printf '%s' "$1" | jq -r ' + def v: if . == null then "-" else tostring end; + def sha: if . == null then "-" else .[0:12] end; + "wrap-session/1 generated_at=\(.generated_at) epoch=\(.generated_at_epoch) repos=\(.summary.repos) open_own_prs=\(.summary.open_own_prs) pending_prs=\(.summary.pending_prs) named_prs=\(.summary.named_prs) foreign_activity_repos=\(.summary.foreign_activity_repos)", + "config " + (.config | to_entries | map("\(.key)=\(.value | v)") | join(" ")), + "activity_log configured=\(.activity_log.configured) target=\(.activity_log.resolved | v) writable=\(.activity_log.writable) error=\(.activity_log.error | v)", + (.named_prs // null | select(. != null) | + "named_prs read_at=\(.read_at) gh=\(.gh_state) error=\(.error | v)", + (.rows[] | if .error then " pr \(.ref) ERROR \(.error)" + else " pr \(.ref) state=\(.state) merged=\(.merged) merged_at=\(.merged_at | v) merge=\(.merge_sha | sha) head=\(.head_branch | v) draft=\(.draft) author=\(.author | v) \"\(.title)\"" end)), + (.repos[] | + if .is_repo != true then "repo \(.path) NOT A REPO: \(.error | v)" else + "repo \(.path) slug=\(.github_slug | v) default=\(.default_branch | v) branch=\(.checkout.branch | v) ahead=\(.checkout.ahead | v) behind=\(.checkout.behind | v) dirty=\(.checkout.dirty_files | length) index_lock=\(.checkout.index_lock.present) fetch=\"\(.fetch_error | v)\"", + (.writers // null | select(. != null) | + " writers foreign_activity=\(.foreign_activity) mark=\(.writer_mark.write | v) mark_error=\(.writer_mark.error | v)", + (.worktrees[] | select(.foreign_activity) | " foreign \(.path) branch=\(.branch | v) index_lock=\(.index_lock.present) reflog_newer=\(.reflog.newer_than_since | v)")), + (.checkout.dirty_files[] | " dirty \(.)"), + (.checkout.worktrees[] | " worktree \(.path) branch=\(.branch // "detached")"), + (if .board.present then + " board file=\(.board.file) wrapper=\(.board.wrapper | v) open_rows=\(.board.rows | length)", + (.board.rows[] | " row \(.id) \(.state) \(.title[0:90])") + else " board none" end), + " handoffs exit=\(.handoffs.exit_code) error=\(.handoffs.error | v)", + (.handoffs.lines[] | " \(.)"), + " prs gh=\(.pull_requests.gh_state) error=\(.pull_requests.error | v) dispatch_workflows=\((.pull_requests.dispatch_workflows // []) | join(",") | if . == "" then "-" else . end)", + (.pull_requests.open_own[]? | " open #\(.number) gate=\"\(.gate)\" draft=\(.isDraft // false) checks=\(.checks.total // 0)/pending \(.checks.pending // 0)/failed \(.checks.failed // 0) head=\(.headRefName | v) \"\(.title // "")\"", + ((.checks.latest // [])[] | select(((.conclusion // "") | ascii_upcase) as $c | $c != "SUCCESS" and $c != "SKIPPED" and $c != "NEUTRAL") | " check \(.name) \(.status // "-") \(.conclusion // "pending")")), + (.pull_requests as $p | $p.merged_recent[]? | . as $m + | ([$p.deploys[]? | select(.pr == $m.number)][0] // {}) as $d + | " merged #\(.number) at=\(.mergedAt | v) merge=\(.merge_sha | sha) deploy=\($d.state // "-") head=\(.headRefName | v) \"\(.title // "")\""), + (.sweep | if .format == "json" then + (.document.repos[]? | + " sweep " + ((.rows // []) | group_by(.verdict) | map("\(.[0].verdict)=\(length)") | join(" ") | if . == "" then "rows=0" else . end) + (if .error then " error=\"\(.error)\"" else "" end), + ((.rows // [])[] | select(.verdict != "keep") | " \(.verdict) \(.kind) \(.branch // .path | v) \(.reason)")) + else " sweep text-fallback (read-only, no fetch): see --json" end) + end)' 2>/dev/null +} + # _session_repo_json -- one repo object. Every child read degrades into a field, # never into extra stdout, so the final document stays machine-readable. _session_repo_json() { @@ -605,14 +710,21 @@ _session_repo_json() { cmd_session() { local json=0 follow="" arg count=0 start end duration tmp repos config activity local writers=0 writers_text=0 since_json=null start_epoch writers_out check_mark="" write_mark="" + local summary=0 mark_dir="" refs="" named='null' repo_out wjson key out local wusage="usage: wrap.sh session --writers [--since ] [--check-mark ] [--mark ] [--self ]... [--text] " - local -a repos_args=() selfs=() + local gusage="usage: wrap.sh session --json|--summary [--prs owner/name#n,...] [--mark-dir [--since ] [--self ]...] [--follow-mode lanes|all] [...]" + local -a repos_args=() selfs=() pr_words=() while [ $# -gt 0 ]; do arg="$1" case "$arg" in --json) json=1 ;; + --summary) summary=1 ;; --writers) writers=1 ;; --text) writers_text=1 ;; + --prs) [ $# -ge 2 ] || { echo "$gusage" >&2; return 64; } + pr_words+=("$2"); shift 2; continue ;; + --mark-dir) [ $# -ge 2 ] || { echo "$gusage" >&2; return 64; } + mark_dir="$2"; shift 2; continue ;; --since) [ $# -ge 2 ] || { echo "$wusage" >&2; return 64; } case "$2" in ''|*[!0-9]*) echo "wrap.sh session --since: epoch must be a whole number" >&2; return 64 ;; esac since_json="$2"; shift 2; continue ;; @@ -635,6 +747,9 @@ cmd_session() { if [ "$writers" = 1 ]; then [ "$count" -eq 1 ] || { echo "$wusage" >&2; return 64; } + if [ "${#pr_words[@]}" -gt 0 ] || [ -n "$mark_dir" ] || [ "$summary" = 1 ]; then + echo "wrap.sh session --writers: --prs, --mark-dir and --summary belong to the gather" >&2; return 64 + fi if [ "$since_json" = "null" ]; then case "${WRAP_SESSION_START:-}" in ''|*[!0-9]*) ;; *) since_json="$WRAP_SESSION_START" ;; esac fi @@ -654,28 +769,74 @@ cmd_session() { return 0 fi - [ "$json" = 1 ] && [ "$count" -ge 1 ] || { echo "usage: wrap.sh session --json [--follow-mode lanes|all] [...]" >&2; return 64; } + # On the gather, `--text` (the writers text switch) asks for the summary view. + [ "$writers_text" = 1 ] && summary=1 + if [ "$json" = 1 ] && [ "$summary" = 1 ]; then + echo "wrap.sh session: --json and --summary are two views of one gather; pick one" >&2; return 64 + fi + { [ "$json" = 1 ] || [ "$summary" = 1 ]; } && [ "$count" -ge 1 ] || { echo "$gusage" >&2; return 64; } + if [ -n "$write_mark" ] || [ -n "$check_mark" ]; then + echo "wrap.sh session: --mark and --check-mark belong to --writers; the gather takes --mark-dir" >&2; return 64 + fi + if [ "${#pr_words[@]}" -gt 0 ]; then + refs="$(_session_pr_refs "${pr_words[@]}")" || return 64 + fi + if [ -n "$mark_dir" ]; then + mkdir -p "$mark_dir" 2>/dev/null && [ -d "$mark_dir" ] && [ -w "$mark_dir" ] \ + || { echo "wrap.sh session --mark-dir: '$mark_dir' is not a writable directory" >&2; return 64; } + mark_dir="$(cd "$mark_dir" && pwd -P)" + if [ "$since_json" = "null" ]; then + case "${WRAP_SESSION_START:-}" in ''|*[!0-9]*) ;; *) since_json="$WRAP_SESSION_START" ;; esac + fi + fi start_epoch="$(date +%s)"; start=$(( start_epoch * 1000 )) tmp="$(mktemp "${TMPDIR:-/tmp}/kit.XXXXXX")" _session_open_states >/dev/null || { rm -f "$tmp"; return 1; } - for arg in "${repos_args[@]}"; do _session_repo_json "$arg" >> "$tmp" || { rm -f "$tmp"; return 1; }; done + for arg in "${repos_args[@]}"; do + # With --mark-dir, step 0's writer check and mark ride the same call, taken before the + # repo is read: one mark file per repo, keyed by its slash-free path. + wjson="" + if [ -n "$mark_dir" ]; then + key="$(_session_abs_path "$arg" | sed 's#^/##; s#/#-#g')" + if [ "${#selfs[@]}" -eq 0 ]; then + wjson="$(_session_writers_json "$arg" "$since_json" "" "$mark_dir/writers-$key.json")" + else + wjson="$(_session_writers_json "$arg" "$since_json" "" "$mark_dir/writers-$key.json" "${selfs[@]}")" + fi + fi + repo_out="$(_session_repo_json "$arg")" || { rm -f "$tmp"; return 1; } + if [ -n "$wjson" ]; then + printf '%s' "$repo_out" | jq -c --argjson w "$wjson" '. + {writers:$w}' >> "$tmp" + else + printf '%s\n' "$repo_out" >> "$tmp" + fi + done repos="$(jq -s . "$tmp" 2>/dev/null)"; [ -n "$repos" ] || repos='[]' rm -f "$tmp" + [ -n "$refs" ] && named="$(_session_named_prs_json "$refs")" + [ -n "$named" ] || named='null' config="$(_session_config_json "$follow")" activity="$(_session_activity_json)" end=$(( $(date +%s) * 1000 )); duration=$(( end - start )) - jq -cn --arg started_at "$(date -u +%Y-%m-%dT%H:%M:%SZ)" --argjson started_epoch "$start_epoch" \ - --argjson duration_ms "$duration" \ + out="$(jq -cn --arg started_at "$(date -u +%Y-%m-%dT%H:%M:%SZ)" --argjson started_epoch "$start_epoch" \ + --argjson duration_ms "$duration" --argjson named "$named" \ --argjson repos "$repos" --argjson config "$config" --argjson activity "$activity" \ '{schema:"wrap-session/1",generated_at:$started_at,generated_at_epoch:$started_epoch,duration_ms:$duration_ms, - config:$config.wrap,activity_log:$activity,repos:$repos, + config:$config.wrap,activity_log:$activity,named_prs:$named,repos:$repos, summary:{repos:($repos|length), invalid_repos:([$repos[] | select(.is_repo != true)] | length), open_own_prs:([$repos[].pull_requests.open_own[]?] | length), pending_prs:([$repos[].pull_requests.open_own[]? | select((.checks.pending // 0) > 0)] | length), + named_prs:(($named.rows // []) | length), + foreign_activity_repos:([$repos[] | select(.writers.foreign_activity == true)] | length), sweep_would_remove:([$repos[].sweep.document.summary.would_remove? // 0] | add // 0), - sweep_rows:([$repos[].sweep.document.repos[]?.rows[]?] | length)}}' + sweep_rows:([$repos[].sweep.document.repos[]?.rows[]?] | length)}}')" + if [ "$summary" = 1 ]; then + _session_summary_text "$out" + else + printf '%s\n' "$out" + fi return 0 } diff --git a/tests/test-wrap-session.sh b/tests/test-wrap-session.sh index ed57aa52..aa016d12 100755 --- a/tests/test-wrap-session.sh +++ b/tests/test-wrap-session.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash # test-wrap-session.sh -- the read-only session gather: schema, PR checks, deploy state, -# the sweep seam and its apply dry-run fallback, and the no-write contract. +# the sweep seam and its apply dry-run fallback, the no-write contract, and the one-call +# gather: named PRs read live in one GraphQL batch (--prs), the --summary view, --mark-dir. # modules under test: lib/wrap/wrap.sh lib/wrap/wrap-common.sh lib/wrap/wrap-scan.sh lib/wrap/wrap-session.sh lib/wrap/wrap-ci.sh lib/wrap/wrap-merge.sh KIT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" source "$KIT_DIR/tests/lib/wrap-stub.sh" @@ -236,6 +237,142 @@ out="$(WRAP_SESSION_WRAP_BIN="$fake" "$kitcp/bin/wrap" session --json "$clone" 2 chk "a state with a regex character still exits 0" "$rc" jqok "a state is matched by equality: a.b is open, aXb is not" "$out" '[.repos[0].board.rows[].id] == ["DK-201","DK-203"]' +# =========================================================================== +# The one-call gather: --prs (named PRs, one batched GraphQL read), --summary, --mark-dir. +# =========================================================================== + +make_clone prs rmain main main +clone="$TMPD/clone-prs" +fake="$TMPD/fake-wrap-prs" +cat > "$fake" < "$TMPD/gh-gql/gh" <<'GHGQL' +#!/usr/bin/env bash +if [ "${1:-} ${2:-}" = "api graphql" ]; then + printf '%s\n' "$*" >> "$GQL_STUB_CALLS" + printf '%s\n' "$GQL_STUB_JSON" + exit "${GQL_STUB_RC:-0}" +fi +exec "$TMPD_STUB_GH" "$@" +GHGQL +chmod +x "$TMPD/gh-gql/gh" +export TMPD_STUB_GH="$TMPD/stub/gh" GQL_STUB_CALLS="$TMPD/gql.calls" +gather() { PATH="$TMPD/gh-gql:$PATH" WRAP_SESSION_WRAP_BIN="$fake" "$WRAP" session "$@"; } + +gql_doc='{"data":{ + "r0":{"p6190":{"number":6190,"title":"feat: verbatim post","url":"https://github.com/acme/ops/pull/6190","state":"MERGED","merged":true,"mergedAt":"2026-11-26T04:30:12Z","mergeCommit":{"oid":"eb792834f92d0000000000000000000000000000"},"headRefName":"feat/post","baseRefName":"main","isDraft":false,"author":{"login":"me"}}, + "p7":{"number":7,"title":"still open","url":"https://github.com/acme/ops/pull/7","state":"OPEN","merged":false,"mergedAt":null,"mergeCommit":null,"headRefName":"feat/x","baseRefName":"main","isDraft":false,"author":{"login":"me"}}, + "p999":null}, + "r1":{"p1051":{"number":1051,"title":"fix(link-bot): same chat","url":"https://github.com/acme/dots/pull/1051","state":"MERGED","merged":true,"mergedAt":"2026-11-26T04:47:05Z","mergeCommit":{"oid":"4cf53e1aee370000000000000000000000000000"},"headRefName":"fix/same-chat","baseRefName":"main","isDraft":false,"author":{"login":"me"}}}}, + "errors":[{"type":"NOT_FOUND","path":["r0","p999"],"message":"Could not resolve to a PullRequest with the number of 999."}]}' + +# =========================================================================== +echo "=== --prs: every named PR, one batched GraphQL call, live state ===" +# =========================================================================== +: > "$GQL_STUB_CALLS" +out="$(GQL_STUB_JSON="$gql_doc" GQL_STUB_RC=1 gather --json --prs "acme/ops#6190,acme/ops#7" --prs https://github.com/acme/dots/pull/1051 --prs acme/ops#999 --prs acme/ops#7 "$clone" 2>/dev/null)"; rc=$? +chk "a gather with --prs exits 0 even when gh exits 1 on a partial error" "$rc" +chk "four distinct refs across two repos cost exactly one GraphQL call" "$([ "$(wc -l < "$GQL_STUB_CALLS" | tr -d ' ')" = 1 ]; echo $?)" +q="$(cat "$GQL_STUB_CALLS")" +chk_has "the query aliases the first repo" "$q" 'r0: repository(owner: "acme", name: "ops")' +chk_has "the query aliases the second repo" "$q" 'r1: repository(owner: "acme", name: "dots")' +chk_has "the query reads the merge state live" "$q" "merged mergedAt mergeCommit { oid } headRefName" +jqok "every ref is a row, duplicates folded, in input order" "$out" '[.named_prs.rows[].ref] == ["acme/ops#6190","acme/ops#7","acme/dots#1051","acme/ops#999"]' +jqok "a merged PR carries state, merged, mergedAt, merge commit and head branch" "$out" '.named_prs.rows[0] | .state == "MERGED" and .merged == true and .merged_at == "2026-11-26T04:30:12Z" and .merge_sha == "eb792834f92d0000000000000000000000000000" and .head_branch == "feat/post" and .error == null' +jqok "an open PR reads OPEN, never a cached merged state" "$out" '.named_prs.rows[1] | .state == "OPEN" and .merged == false and .merge_sha == null' +jqok "a URL ref resolves like owner/name#n" "$out" '.named_prs.rows[2] | .number == 1051 and .state == "MERGED"' +jqok "an unresolvable PR stays a row with GitHub's error" "$out" '.named_prs.rows[3] | (.error | test("Could not resolve")) and .state == null' +jqok "the read is stamped and counted" "$out" '(.named_prs.read_at | test("^20")) and .named_prs.gh_state == "ok" and .summary.named_prs == 4' + +out="$(GQL_STUB_JSON='not json' GQL_STUB_RC=1 gather --json --prs acme/ops#7 "$clone" 2>/dev/null)"; rc=$? +chk "a failed GraphQL read still exits 0" "$rc" +jqok "a failed read keeps the ref as a row with an error" "$out" '.named_prs.rows == [{"ref":"acme/ops#7","error":"graphql read failed"}]' + +: > "$GQL_STUB_CALLS" +out="$(GH_STUB_UNAUTH=1 GQL_STUB_JSON="$gql_doc" gather --json --prs acme/ops#7 "$clone" 2>/dev/null)"; rc=$? +chk "an unauthenticated gh still exits 0" "$rc" +jqok "unauthenticated gh is a field on every named row" "$out" '.named_prs.gh_state == "unauthenticated" and .named_prs.rows[0].error == "gh unauthenticated"' +chk "an unauthenticated gh makes no GraphQL call" "$([ ! -s "$GQL_STUB_CALLS" ]; echo $?)" + +for bad in 'acme/ops' 'acme/ops#x' 'ac"me/ops#1' 'acme/ops#1) { x }' '../x#1'; do + out="$(gather --json --prs "$bad" "$clone" 2>&1)"; rc=$? + chk "a malformed ref '$bad' is refused with exit 64" "$([ "$rc" -eq 64 ]; echo $?)" +done +chk_has "the refusal names the expected shape" "$out" "is not owner/name#n" + +out="$(gather --json "$clone" 2>/dev/null)" +jqok "without --prs the document says named_prs is null" "$out" '.named_prs == null and .summary.named_prs == 0' + +# =========================================================================== +echo "=== --summary: one compact view of the same gather ===" +# =========================================================================== +mkdir -p "$clone/_meta" +cat > "$clone/_meta/BACKLOG.md" <<'BOARD' +| ID | Title | State | +|---|---|---| +| DK-101 | wrap session gather | executing | +| DK-102 | old shipped row | shipped | +BOARD +open7='{"number":7,"title":"wrap the session","headRefName":"feat/wrap","headRefOid":"deadbeefcafe1234567890abcdef1234567890ab","baseRefName":"main","mergeable":"MERGEABLE","mergeStateStatus":"UNSTABLE","reviewDecision":"APPROVED","statusCheckRollup":[{"name":"test","status":"IN_PROGRESS"},{"name":"lint","conclusion":"FAILURE"}],"isDraft":false}' +sum="$(GH_STUB_PR_7="$open7" GQL_STUB_JSON="$gql_doc" gather --summary --prs acme/ops#6190,acme/ops#999 "$clone" 2>/dev/null)"; rc=$? +chk "the summary exits 0" "$rc" +chk "the summary is not JSON" "$(printf '%s' "$sum" | jq -e . >/dev/null 2>&1 && echo 1 || echo 0)" +chk_has "the header line carries the counts" "$sum" "wrap-session/1 generated_at=" +chk_has "the header counts the named PRs" "$sum" "named_prs=2" +chk_has "config knobs are one line" "$sum" "config distill=" +chk_has "config carries the follow mode" "$sum" "follow_mode=" +chk_has "the activity log has its line" "$sum" "activity_log configured=" +chk_has "a named merged PR prints its live state and merge commit" "$sum" "pr acme/ops#6190 state=MERGED merged=true merged_at=2026-11-26T04:30:12Z merge=eb792834f92d head=feat/post" +chk_has "a named PR GitHub cannot resolve prints ERROR" "$sum" "pr acme/ops#999 ERROR Could not resolve" +chk_has "the repo line carries branch, counts and fetch state" "$sum" "default=main branch=main ahead=0 behind=0 dirty=1 index_lock=false" +chk_has "the untracked board dir is a dirty line" "$sum" "dirty ?? _meta/" +chk_has "worktrees are listed" "$sum" "worktree $TMPD_P/wt-prs-clean branch=wt-clean" +chk_has "an open board row is listed" "$sum" "row DK-101 executing wrap session gather" +chk_no "a terminal board row is not listed" "$sum" "DK-102" +chk_has "an own open PR prints gate and check totals" "$sum" "open #7 gate=" +chk_has "an own open PR prints pending and failed counts" "$sum" "checks=2/pending 1/failed 1" +chk_has "a failing check is named" "$sum" "check lint - FAILURE" +chk_has "a running check is named" "$sum" "check test IN_PROGRESS pending" +chk_has "the sweep collapses to verdict counts" "$sum" "sweep keep=" +chk_has "a non-keep sweep row is listed with its reason" "$sum" "would_remove worktree fix/a PR #12 merged, clean" +chk_no "keep sweep rows are only counted" "$sum" "fresh branch, no own commits" +txt="$(GH_STUB_PR_7="$open7" gather --text "$clone" 2>/dev/null)" +chk_has "--text on the gather is the summary view" "$txt" "wrap-session/1 generated_at=" +out="$(gather --json --summary "$clone" 2>&1)"; rc=$? +chk "--json with --summary is refused" "$([ "$rc" -eq 64 ]; echo $?)" + +# =========================================================================== +echo "=== --mark-dir: step 0's writer check rides the gather ===" +# =========================================================================== +mkdir -p "$TMPD/marks"; marks="$TMPD/marks" +since=$(( $(date +%s) - 3600 )) +out="$(gather --json --mark-dir "$marks" --since "$since" --self "$TMPD/wt-prs-clean" "$clone" 2>/dev/null)"; rc=$? +chk "a gather with --mark-dir exits 0" "$rc" +key="$(cd "$clone" && pwd -P | sed 's#^/##; s#/#-#g')" +marks="$(cd "$marks" && pwd -P)" +chk "the mark file is written under a slash-free repo key" "$([ -f "$marks/writers-$key.json" ]; echo $?)" +jqok "the repo row carries the writer facts and the mark path" "$out" ".repos[0].writers.schema == \"wrap-writers/1\" and .repos[0].writers.writer_mark.write == \"$marks/writers-$key.json\" and .repos[0].writers.since == $since" +chk "the written mark passes the later --check-mark" "$("$WRAP" session --writers --check-mark "$marks/writers-$key.json" --self "$TMPD/wt-prs-clean" "$clone" 2>/dev/null | jq -e '.writer_mark.valid == true' >/dev/null; echo $?)" +gda="$(git -C "$clone" rev-parse --path-format=absolute --git-dir)" +: > "$gda/index.lock" +sum="$(gather --summary --mark-dir "$marks" --self "$TMPD/wt-prs-clean" "$clone" 2>/dev/null)" +rm -f "$gda/index.lock" +chk_has "foreign activity shows in the summary" "$sum" "writers foreign_activity=true" +chk_has "the foreign worktree is named" "$sum" "foreign $TMPD_P/clone-prs branch=main index_lock=true" +chk_has "the header counts repos with foreign activity" "$sum" "foreign_activity_repos=1" +out="$(gather --json --mark "$TMPD/x.json" "$clone" 2>&1)"; rc=$? +chk "--mark on the gather is refused (it belongs to --writers)" "$([ "$rc" -eq 64 ]; echo $?)" +out="$("$WRAP" session --writers --prs acme/ops#1 "$clone" 2>&1)"; rc=$? +chk "--prs on --writers is refused" "$([ "$rc" -eq 64 ]; echo $?)" + echo if [ "$FAIL" -gt 0 ]; then echo "test-wrap-session: $PASS passed, $FAIL FAILED of $TOTAL" >&2; exit 1; fi echo "test-wrap-session: all $PASS passed" From 3280f9b96ab26d5ab7ab8695cbc037218f376907 Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 10:50:55 +0700 Subject: [PATCH 02/19] docs(verification): add proof for wrap-cut-call --- docs/verification/wrap-cut-call.md | 95 ++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 docs/verification/wrap-cut-call.md diff --git a/docs/verification/wrap-cut-call.md b/docs/verification/wrap-cut-call.md new file mode 100644 index 00000000..df46515e --- /dev/null +++ b/docs/verification/wrap-cut-call.md @@ -0,0 +1,95 @@ +# Verification: wrap-cut-call + +Headless shell library and command-file change (`feat-wrap-cut-call`, off `origin/master` at `e75b5b2d`): no visible surface. + +An A/B replay of `/kit:wrap` (ops-toolkit `experiments/wrap-ab-replay/`) found the new command worse than the old one on 2 of 6 sessions: B4 stated a stale PR state, and P3 printed `Needs you: NOTHING` while the owner still had an action. It also counted 127 lead calls over 6 wraps, against a target of 10 per wrap. This change gives `wrap session` the flags that let `commands/wrap.md` run one gather call, and adds a needs-you check. + +## What changed + +1. `lib/wrap/wrap-session.sh`, on the gather (not `--writers`): + - `--prs owner/name#n,...` (also `https://github.com/owner/name/pull/n`, repeatable) resolves every ref in ONE `gh api graphql` call: state, merged, mergedAt, merge commit, head branch, base, draft, author. Refs are validated before they enter the query text. A ref GitHub cannot resolve stays a row with GitHub's error; no ref is dropped. A non-ok `gh` makes no call and marks each row. + - `--summary` prints the gather as one fact per line (`--text` means the same on the gather). Sweep keep rows collapse to a count. + - `--mark-dir ` (with `--since`, `--self`) runs step 0's writer check and mark per repo inside the gather, writing `/writers-.json`. +2. `commands/wrap.md`: one `session recall --replies` digest, one gather, then the report. It names the calls the gather replaces, finds handed-off PRs with one live `gh pr list --search`, re-gathers only after a write, and walks the digest for owner actions before `Needs you` may say `NOTHING`. + +## Green runs + +```text +Command: bash tests/test-wrap-session.sh +Exit: 0 +Output: +=== --prs: every named PR, one batched GraphQL call, live state === + PASS a gather with --prs exits 0 even when gh exits 1 on a partial error + PASS four distinct refs across two repos cost exactly one GraphQL call + PASS an open PR reads OPEN, never a cached merged state + PASS an unresolvable PR stays a row with GitHub's error +=== --summary: one compact view of the same gather === + PASS a named merged PR prints its live state and merge commit + PASS an own open PR prints pending and failed counts +=== --mark-dir: step 0's writer check rides the gather === + PASS the written mark passes the later --check-mark + PASS foreign activity shows in the summary +test-wrap-session: all 122 passed +Verdict: PASS +``` + +```text +Command: for t in test-meta-spec-depth test-wrap-report-lint test-wrap-cli test-wrap-start test-wrap-land test-wrap-ship test-wrap-rebase test-wrap-deploy test-meta-docs-registry test-ship-gate-impl-notes test-ship-pr-body-verified test-gate-validate-round; do bash tests/$t.sh; done +Exit: 0 +Output: +test-meta-spec-depth: All meta tests passed. +test-wrap-report-lint: all 159 passed +test-wrap-cli: all 106 passed +test-wrap-start: all 143 passed +test-wrap-land: all 889 passed +test-wrap-ship: all 120 passed +test-wrap-rebase: all 104 passed +test-wrap-deploy: all 176 passed +test-meta-docs-registry: Passed 123 / 123 +test-ship-gate-impl-notes: PASS=19 FAIL=0 +test-ship-pr-body-verified: 7/7 passed +test-gate-validate-round: 202/202 pass, 0 fail +Verdict: PASS (every suite that reads commands/wrap.md) +``` + +```text +Command: shellcheck -s bash -x lib/wrap/wrap-session.sh +Exit: 0 +Output: +(no findings) +Verdict: PASS +``` + +## Negative control + +```text +Command: bash scripts/negctl.sh "bash tests/test-wrap-session.sh" "git show origin/master:lib/wrap/wrap-session.sh >| lib/wrap/wrap-session.sh" +Exit: 1 +Output: + FAIL --text on the gather is the summary view + PASS --json with --summary is refused +=== --mark-dir: step 0's writer check rides the gather === + FAIL a gather with --mark-dir exits 0 + FAIL the mark file is written under a slash-free repo key + FAIL the repo row carries the writer facts and the mark path + FAIL the written mark passes the later --check-mark + FAIL foreign activity shows in the summary + FAIL the foreign worktree is named + FAIL the header counts repos with foreign activity + FAIL --mark on the gather is refused (it belongs to --writers) + PASS --prs on --writers is refused + +test-wrap-session: 78 passed, 44 FAILED of 122 +Verdict: RED, as expected +``` + +The 11 new cases that pass on master are refusals (master refuses the unknown flags with exit 64 too) and two `chk_no` lines. + +## Not proven locally + +- The full suite (`bash tests/run-all.sh`) did not run: the host was loaded, so only the suites that read the touched files ran. CI is the second opinion. +- `wrap.sh` usage and `docs/reference/wrap.md` do not yet name the new flags: another session holds those files. + +## Rollback + +Revert the commit. The new flags are additive; `--json` output only gains `named_prs` and two summary counts. From 2d845291863a7a62ffb453372b4557d5e82651b0 Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 11:02:39 +0700 Subject: [PATCH 03/19] feat(wrap): gather reads the target transcript itself The first replay of the one-call wrap cut wall time and tokens about 3x but left a median of 15.5 lead calls: the lead still mined the transcript for repo paths and the start epoch. wrap session --transcript now reads the lead and subagent transcripts in the script: the start epoch (first timestamp, the writer threshold unless --since is given), every GitHub PR URL (added to the batched --prs read), and the main checkout of every repo the session worked in. Named PRs also carry their merge commit's check state. commands/wrap.md passes --transcript, lists the reads it replaces (git log, wrap apply dry runs, gh run list, --help, repo hunting), and gives the one flick-7b call form. ## How I verified it bash tests/test-wrap-session.sh -> test-wrap-session: all 131 passed --- commands/wrap.md | 13 +++--- lib/wrap/wrap-session.sh | 85 +++++++++++++++++++++++++++++++++----- tests/test-wrap-session.sh | 32 +++++++++++++- 3 files changed, 112 insertions(+), 18 deletions(-) diff --git a/commands/wrap.md b/commands/wrap.md index 34abbd86..d15f3adb 100644 --- a/commands/wrap.md +++ b/commands/wrap.md @@ -16,19 +16,20 @@ The distill half is the candidate scan, both seams, steps 7a-7c, and the drain. ## Start gather -Bracket timing: `bash lib/gate/gate-ledger.sh outcome wrap start`. Resolve each main checkout once from a worktree with `git -C rev-parse --path-format=absolute --git-common-dir` minus `/.git`. Pass one `--self` for every worktree the target session owns: its EnterWorktree, every `agent-*` subagent worktree, and every `wrap start` worktree. Pass every PR the digest names, own or not, in `--prs`. Then run the whole gather as ONE call: +Bracket timing: `bash lib/gate/gate-ledger.sh outcome wrap start`. Resolve each main checkout once from a worktree with `git -C rev-parse --path-format=absolute --git-common-dir` minus `/.git`. Pass one `--self` for every worktree the target session owns: its EnterWorktree, every `agent-*` subagent worktree, and every `wrap start` worktree. Then run the whole gather as ONE call: ```bash -bin/wrap session --summary --prs ,... --mark-dir "$scratch" --since [--self ]... [--follow-mode lanes|all] ... +bin/wrap session --summary [--transcript ] --mark-dir "$scratch" [--since ] [--prs ,...] [--self ]... [--follow-mode lanes|all] [...] ``` -- `--prs` reads every named PR live, in one batched GitHub call: state, merged, mergedAt, merge commit, head branch. A PR's state in the report comes from this read, never from the transcript. -- `--mark-dir` is step 0's check for activity before the wrap, taken per repo before the repo is read. It records each writer mark as `writers_mark="$scratch/writers-.json"`, the repo's absolute path without its leading slash and with `/` as `-`; the `writers` line prints the path. Its `foreign_activity` (an `index.lock`, or a reflog row newer than the session start in any worktree except the session's own, the main checkout included) stops the repo exactly as the landing pass describes. Use the target session's real start epoch; without one, use the time this wrap started. +- `--transcript` (always, when wrapping another session; a self-wrap whose transcript path is unknown passes its repos and `--since`) makes the script read the target transcript and its subagent transcripts, so you never do. It adds every repo the session worked in (each cwd, Edit or Write path, `git -C` or `cd` target, resolved to its main checkout), every GitHub PR URL, and the session start epoch (the first timestamp, the writer-check threshold unless you pass `--since`). Never look for repo paths, PR numbers or the start time yourself. Name a `` or a `--prs` ref only when the digest names one the `transcript` line lacks. +- `--prs` and the transcript's PRs are read live, in one batched GitHub call: state, merged, mergedAt, merge commit, its check state, head branch. A PR's state in the report comes from this read, never from the transcript. A named PR whose repo has no local checkout needs none: its live row is the fact. +- `--mark-dir` is step 0's check for activity before the wrap, taken per repo before the repo is read. It records each writer mark as `writers_mark="$scratch/writers-.json"`, the repo's absolute path without its leading slash and with `/` as `-`; the `writers` line prints the path. Its `foreign_activity` (an `index.lock`, or a reflog row newer than the session start in any worktree except the session's own, the main checkout included) stops the repo exactly as the landing pass describes. The `--transcript` start epoch is the target session's real start; without a transcript, pass `--since` with the time this wrap started. - `--summary` prints every field this command reads, one fact per line. Read it once. `--json` prints the same gather as one `wrap-session/1` document for a tool; never re-read either with `jq`. The gather holds config knobs, activity-log state, the named PRs, and per repo the checkout, dirty files, worktrees, writer facts, active board rows, handoffs, own open PRs with check totals and gates, recent merge deploy state, and the sweep report. Treat it as facts, not as proof of intent. Rows this session did not touch stay untouched. -**What the gather replaces.** Run none of these when the gather covers the fact: `git status`, `git for-each-ref` or any other git ref read; `wrap scan`; a grep, `rg`, `jq` or Read over the transcript; a re-read of the gather; `gh pr view` one PR at a time (put the PR in `--prs`). The target is 10 lead calls per wrap: this file, the digest, the gather, the step 7b lookups, `flick-7b`, and only the writes a decision needs. +**What the gather replaces.** Run none of these when the gather covers the fact: `git status`, `git log`, `git for-each-ref` or any other git read; `wrap scan` or a `wrap apply` dry run (the summary's `sweep` lines carry its verdicts); a grep, `rg`, `jq`, Glob or Read over the transcript or to find a repo; a re-read of the gather; `gh pr view` or `gh run list` one PR at a time (put the PR in `--prs`); a `--help` call. The target is 10 lead calls per wrap: this file, the digest, the gather, the step 7b lookups, one `flick-7b`, and only the writes a decision needs. **Handed-off work.** A change the session handed to another agent or bot ("X will open the PR") has no ref in the digest. Find it with one `gh pr list --repo --state all --search ""` and state only what that live read shows. Never call a PR or a handed-off change pending, open, or merged from the transcript alone. @@ -69,7 +70,7 @@ Landing retro: after the per-repo pass, run `/kit:retro` only when a run ledger Step 7a writes the DEBT marker. Every skip in 7a skips only 7a; 7b and 7c still run. Capture `rid_out` and `rid_rc` exactly. A non-zero `rid_rc` prints `skipped (structural): DEBT marker impossible this run ()`; Do not synthesize a rid. Then use the run log and `bash lib/classify/significance-classify.sh record ""`. A configured teacher from `bash lib/gate/quiz-gate.sh teacher` receives the record; empty prints `skipped: no teacher`. -Step 7b acts on the scan list written before landing, never on a fresh recollection. For each candidate run `bin/precedent find --surface inventory --json`, open the top hit before deciding, and prefer a code home over prose. Then classify with `bash lib/classify/lane-classify.sh risk`. `wrap.build_candidates` false still classifies and reports. `wrap.build_lanes` decides which lanes build inline; `full` never builds inline. Build in the home repo through `bin/wrap start /`, dispatch a worker, verify once, and report the quoted check. Sonnet is the default worker; Opus takes security, money, data models, and verification; Haiku takes mechanical fan-out. Everything else is REPORTED in the report only: it never mints a board row or a staging block. A whole-cover hit is a NOTE with a pointer written in-session. Run `bin/wrap flick-7b` even with empty stdin and carry its `STATE` row verbatim. +Step 7b acts on the scan list written before landing, never on a fresh recollection. For each candidate run `bin/precedent find --surface inventory --json`, open the top hit before deciding, and prefer a code home over prose. Then classify with `bash lib/classify/lane-classify.sh risk`. `wrap.build_candidates` false still classifies and reports. `wrap.build_lanes` decides which lanes build inline; `full` never builds inline. Build in the home repo through `bin/wrap start /`, dispatch a worker, verify once, and report the quoted check. Sonnet is the default worker; Opus takes security, money, data models, and verification; Haiku takes mechanical fan-out. Everything else is REPORTED in the report only: it never mints a board row or a staging block. A whole-cover hit is a NOTE with a pointer written in-session. Run `bin/wrap flick-7b` once, piping one ` ` pair per line (with no pair, run it once with empty stdin), and carry its `STATE` row verbatim. Step 7c writes one memory note per incident whose root cause was our mistake, plus its index line. No incidents prints `skipped: no incidents`. For each note written, resolve `bash lib/gate/quiz-gate.sh teacher`; empty prints `skipped: no teacher` with the note path, and a named teacher receives the note path and incident file. The drain of hand-staged rows runs only when `wrap.drain_staged` is true. diff --git a/lib/wrap/wrap-session.sh b/lib/wrap/wrap-session.sh index 0d24ffba..2767c648 100644 --- a/lib/wrap/wrap-session.sh +++ b/lib/wrap/wrap-session.sh @@ -557,6 +557,44 @@ _session_config_json() { build_lanes:$build_lanes,drain_staged:$drain_staged,follow_mode:$follow_mode,follow_lanes:$follow_lanes}}' } +# _session_transcript_json -- the landing facts a script can read from a session +# transcript and its subagent transcripts, so the lead never mines one: the start epoch (first +# timestamp), every GitHub PR URL, and the main checkout of every repo the session worked in (each +# cwd, each Edit/Write path, each `git -C` or `cd` target). A path that no longer exists walks up to +# its nearest existing parent, so a removed worktree still names its repo. +_session_transcript_json() { + local t="$1" start prs paths p d main repos_json + local -a tfiles=("$t") + for p in "${t%.jsonl}"/subagents/*.jsonl; do [ -f "$p" ] && tfiles+=("$p"); done + start="$(jq -r 'select(.timestamp != null) | .timestamp' "$t" 2>/dev/null | head -n 1 \ + | jq -R 'sub("\\.[0-9]+Z$"; "Z") | try fromdateiso8601 catch empty' 2>/dev/null)" + case "$start" in ''|*[!0-9]*) start=null ;; esac + prs="$(cat "${tfiles[@]}" 2>/dev/null | grep -Eo 'https://github\.com/[A-Za-z0-9][A-Za-z0-9-]*/[A-Za-z0-9_.-]+/pull/[0-9]+' \ + | sed -E 's#^https://github\.com/([^/]+)/([^/]+)/pull/([0-9]+)$#\1/\2\#\3#' | awk '!seen[$0]++' | head -n 50 | _session_lines_json)" + [ -n "$prs" ] || prs='[]' + paths="$(jq -r ' + (select(.cwd != null) | .cwd), + (.message.content[]? | select(.type == "tool_use") | .input + | ((.file_path // .notebook_path // empty), + ((.command // "") | [scan("(?:git\\s+-C|\\bcd)\\s+(\"[^\"]+\"|'"'"'[^'"'"']+'"'"'|[^\\s;&|)]+)")[] | .[0]] | .[]))) + ' "${tfiles[@]}" 2>/dev/null | tr -d "\"'" | sed "s#^~/#$HOME/#" | grep '^/' | awk '!seen[$0]++')" + repos_json="$(while IFS= read -r p; do + [ -n "$p" ] || continue + d="$p" + while [ -n "$d" ] && [ "$d" != "/" ] && [ ! -d "$d" ]; do d="$(dirname "$d")"; done + [ -d "$d" ] && [ "$d" != "/" ] && [ "$d" != "$HOME" ] || continue + main="$(_session_main_checkout "$d" 2>/dev/null)" || continue + [ -n "$main" ] && [ "$main" != "$HOME" ] && printf '%s\n' "$main" + done <... -- every PR ref as `owner/name#n`, one per line, deduplicated. # Accepts `owner/name#n` and `https://github.com/owner/name/pull/n`, comma or space separated. # A ref that matches neither shape is an error: it never reaches the GraphQL query text. @@ -597,7 +635,7 @@ _session_named_prs_json() { END { printf "query {" for (i = 0; i < n; i++) { split(order[i], on, "/"); printf " r%d: repository(owner: \"%s\", name: \"%s\") {%s }", i, on[1], on[2], prs[i] } - printf " } fragment F on PullRequest { number title url state merged mergedAt mergeCommit { oid } headRefName baseRefName isDraft author { login } }\n" + printf " } fragment F on PullRequest { number title url state merged mergedAt mergeCommit { oid statusCheckRollup { state } } headRefName baseRefName isDraft author { login } }\n" }')" # gh exits non-zero on a partial GraphQL error but still prints the data, so stdout is read either way. out="$(gh api graphql -f query="$query" 2>/dev/null)" @@ -614,7 +652,8 @@ _session_named_prs_json() { // (if ($doc.data // null) == null then "graphql read failed" else "not found" end))} else {ref:$ref, number:$pr.number, title:$pr.title, url:$pr.url, state:$pr.state, merged:$pr.merged, - merged_at:$pr.mergedAt, merge_sha:($pr.mergeCommit.oid // null), head_branch:$pr.headRefName, + merged_at:$pr.mergedAt, merge_sha:($pr.mergeCommit.oid // null), + merge_checks:($pr.mergeCommit.statusCheckRollup.state // null), head_branch:$pr.headRefName, base_branch:$pr.baseRefName, draft:$pr.isDraft, author:($pr.author.login // null), error:null} end' | jq -s .)" [ -n "$rows" ] || rows='[]' @@ -629,11 +668,14 @@ _session_summary_text() { def sha: if . == null then "-" else .[0:12] end; "wrap-session/1 generated_at=\(.generated_at) epoch=\(.generated_at_epoch) repos=\(.summary.repos) open_own_prs=\(.summary.open_own_prs) pending_prs=\(.summary.pending_prs) named_prs=\(.summary.named_prs) foreign_activity_repos=\(.summary.foreign_activity_repos)", "config " + (.config | to_entries | map("\(.key)=\(.value | v)") | join(" ")), + (.transcript // null | select(. != null) | + "transcript started_at_epoch=\(.started_at_epoch | v) subagent_transcripts=\(.subagent_transcripts) repos=\(.repos | join(",") | if . == "" then "-" else . end) prs=\(.prs | length)"), + "writer_since=\(.since | v)", "activity_log configured=\(.activity_log.configured) target=\(.activity_log.resolved | v) writable=\(.activity_log.writable) error=\(.activity_log.error | v)", (.named_prs // null | select(. != null) | "named_prs read_at=\(.read_at) gh=\(.gh_state) error=\(.error | v)", (.rows[] | if .error then " pr \(.ref) ERROR \(.error)" - else " pr \(.ref) state=\(.state) merged=\(.merged) merged_at=\(.merged_at | v) merge=\(.merge_sha | sha) head=\(.head_branch | v) draft=\(.draft) author=\(.author | v) \"\(.title)\"" end)), + else " pr \(.ref) state=\(.state) merged=\(.merged) merged_at=\(.merged_at | v) merge=\(.merge_sha | sha) merge_checks=\(.merge_checks | v) head=\(.head_branch | v) draft=\(.draft) author=\(.author | v) \"\(.title)\"" end)), (.repos[] | if .is_repo != true then "repo \(.path) NOT A REPO: \(.error | v)" else "repo \(.path) slug=\(.github_slug | v) default=\(.default_branch | v) branch=\(.checkout.branch | v) ahead=\(.checkout.ahead | v) behind=\(.checkout.behind | v) dirty=\(.checkout.dirty_files | length) index_lock=\(.checkout.index_lock.present) fetch=\"\(.fetch_error | v)\"", @@ -710,9 +752,9 @@ _session_repo_json() { cmd_session() { local json=0 follow="" arg count=0 start end duration tmp repos config activity local writers=0 writers_text=0 since_json=null start_epoch writers_out check_mark="" write_mark="" - local summary=0 mark_dir="" refs="" named='null' repo_out wjson key out + local summary=0 mark_dir="" refs="" named='null' repo_out wjson key out transcript="" tjson='null' since_given=0 local wusage="usage: wrap.sh session --writers [--since ] [--check-mark ] [--mark ] [--self ]... [--text] " - local gusage="usage: wrap.sh session --json|--summary [--prs owner/name#n,...] [--mark-dir [--since ] [--self ]...] [--follow-mode lanes|all] [...]" + local gusage="usage: wrap.sh session --json|--summary [--transcript ] [--prs owner/name#n,...] [--mark-dir [--since ] [--self ]...] [--follow-mode lanes|all] [...]" local -a repos_args=() selfs=() pr_words=() while [ $# -gt 0 ]; do arg="$1" @@ -725,9 +767,11 @@ cmd_session() { pr_words+=("$2"); shift 2; continue ;; --mark-dir) [ $# -ge 2 ] || { echo "$gusage" >&2; return 64; } mark_dir="$2"; shift 2; continue ;; + --transcript) [ $# -ge 2 ] || { echo "$gusage" >&2; return 64; } + transcript="$2"; shift 2; continue ;; --since) [ $# -ge 2 ] || { echo "$wusage" >&2; return 64; } case "$2" in ''|*[!0-9]*) echo "wrap.sh session --since: epoch must be a whole number" >&2; return 64 ;; esac - since_json="$2"; shift 2; continue ;; + since_json="$2"; since_given=1; shift 2; continue ;; --self) [ $# -ge 2 ] || { echo "$wusage" >&2; return 64; } selfs+=("$2"); shift 2; continue ;; --mark) [ $# -ge 2 ] || { echo "$wusage" >&2; return 64; } @@ -747,8 +791,8 @@ cmd_session() { if [ "$writers" = 1 ]; then [ "$count" -eq 1 ] || { echo "$wusage" >&2; return 64; } - if [ "${#pr_words[@]}" -gt 0 ] || [ -n "$mark_dir" ] || [ "$summary" = 1 ]; then - echo "wrap.sh session --writers: --prs, --mark-dir and --summary belong to the gather" >&2; return 64 + if [ "${#pr_words[@]}" -gt 0 ] || [ -n "$mark_dir" ] || [ "$summary" = 1 ] || [ -n "$transcript" ]; then + echo "wrap.sh session --writers: --prs, --mark-dir, --transcript and --summary belong to the gather" >&2; return 64 fi if [ "$since_json" = "null" ]; then case "${WRAP_SESSION_START:-}" in ''|*[!0-9]*) ;; *) since_json="$WRAP_SESSION_START" ;; esac @@ -774,6 +818,27 @@ cmd_session() { if [ "$json" = 1 ] && [ "$summary" = 1 ]; then echo "wrap.sh session: --json and --summary are two views of one gather; pick one" >&2; return 64 fi + # --transcript adds the session's own repos, PR URLs and start epoch, read by the script. + if [ -n "$transcript" ]; then + [ -f "$transcript" ] || { echo "wrap.sh session --transcript: '$transcript' is not a file" >&2; return 64; } + tjson="$(_session_transcript_json "$transcript")" + [ -n "$tjson" ] || tjson='null' + # A repo named on the command line is not gathered twice: compare symlink-free paths. + key="" + for arg in ${repos_args[@]+"${repos_args[@]}"}; do key="$key"$'\n'"$(_session_abs_path "$arg")"; done + while IFS= read -r arg; do + [ -n "$arg" ] || continue + case "$key"$'\n' in *$'\n'"$arg"$'\n'*) ;; *) repos_args+=("$arg"); key="$key"$'\n'"$arg" ;; esac + done </dev/null) +EOF_SESSION_TREPOS + pr_words+=("$(printf '%s' "$tjson" | jq -r '.prs | join(",")' 2>/dev/null)") + if [ "$since_given" = 0 ]; then + arg="$(printf '%s' "$tjson" | jq -r '.started_at_epoch // empty' 2>/dev/null)" + case "$arg" in ''|*[!0-9]*) ;; *) since_json="$arg" ;; esac + fi + count="${#repos_args[@]}" + fi { [ "$json" = 1 ] || [ "$summary" = 1 ]; } && [ "$count" -ge 1 ] || { echo "$gusage" >&2; return 64; } if [ -n "$write_mark" ] || [ -n "$check_mark" ]; then echo "wrap.sh session: --mark and --check-mark belong to --writers; the gather takes --mark-dir" >&2; return 64 @@ -821,10 +886,10 @@ cmd_session() { end=$(( $(date +%s) * 1000 )); duration=$(( end - start )) out="$(jq -cn --arg started_at "$(date -u +%Y-%m-%dT%H:%M:%SZ)" --argjson started_epoch "$start_epoch" \ - --argjson duration_ms "$duration" --argjson named "$named" \ + --argjson duration_ms "$duration" --argjson named "$named" --argjson transcript "$tjson" --argjson since "$since_json" \ --argjson repos "$repos" --argjson config "$config" --argjson activity "$activity" \ '{schema:"wrap-session/1",generated_at:$started_at,generated_at_epoch:$started_epoch,duration_ms:$duration_ms, - config:$config.wrap,activity_log:$activity,named_prs:$named,repos:$repos, + config:$config.wrap,activity_log:$activity,transcript:$transcript,since:$since,named_prs:$named,repos:$repos, summary:{repos:($repos|length), invalid_repos:([$repos[] | select(.is_repo != true)] | length), open_own_prs:([$repos[].pull_requests.open_own[]?] | length), diff --git a/tests/test-wrap-session.sh b/tests/test-wrap-session.sh index aa016d12..5062569e 100755 --- a/tests/test-wrap-session.sh +++ b/tests/test-wrap-session.sh @@ -284,7 +284,7 @@ chk "four distinct refs across two repos cost exactly one GraphQL call" "$([ "$( q="$(cat "$GQL_STUB_CALLS")" chk_has "the query aliases the first repo" "$q" 'r0: repository(owner: "acme", name: "ops")' chk_has "the query aliases the second repo" "$q" 'r1: repository(owner: "acme", name: "dots")' -chk_has "the query reads the merge state live" "$q" "merged mergedAt mergeCommit { oid } headRefName" +chk_has "the query reads the merge state live" "$q" "merged mergedAt mergeCommit { oid statusCheckRollup { state } } headRefName" jqok "every ref is a row, duplicates folded, in input order" "$out" '[.named_prs.rows[].ref] == ["acme/ops#6190","acme/ops#7","acme/dots#1051","acme/ops#999"]' jqok "a merged PR carries state, merged, mergedAt, merge commit and head branch" "$out" '.named_prs.rows[0] | .state == "MERGED" and .merged == true and .merged_at == "2026-11-26T04:30:12Z" and .merge_sha == "eb792834f92d0000000000000000000000000000" and .head_branch == "feat/post" and .error == null' jqok "an open PR reads OPEN, never a cached merged state" "$out" '.named_prs.rows[1] | .state == "OPEN" and .merged == false and .merge_sha == null' @@ -330,7 +330,7 @@ chk_has "the header counts the named PRs" "$sum" "named_prs=2" chk_has "config knobs are one line" "$sum" "config distill=" chk_has "config carries the follow mode" "$sum" "follow_mode=" chk_has "the activity log has its line" "$sum" "activity_log configured=" -chk_has "a named merged PR prints its live state and merge commit" "$sum" "pr acme/ops#6190 state=MERGED merged=true merged_at=2026-11-26T04:30:12Z merge=eb792834f92d head=feat/post" +chk_has "a named merged PR prints its live state and merge commit" "$sum" "pr acme/ops#6190 state=MERGED merged=true merged_at=2026-11-26T04:30:12Z merge=eb792834f92d merge_checks=- head=feat/post" chk_has "a named PR GitHub cannot resolve prints ERROR" "$sum" "pr acme/ops#999 ERROR Could not resolve" chk_has "the repo line carries branch, counts and fetch state" "$sum" "default=main branch=main ahead=0 behind=0 dirty=1 index_lock=false" chk_has "the untracked board dir is a dirty line" "$sum" "dirty ?? _meta/" @@ -373,6 +373,34 @@ chk "--mark on the gather is refused (it belongs to --writers)" "$([ "$rc" -eq 6 out="$("$WRAP" session --writers --prs acme/ops#1 "$clone" 2>&1)"; rc=$? chk "--prs on --writers is refused" "$([ "$rc" -eq 64 ]; echo $?)" +# =========================================================================== +echo "=== --transcript: the script reads repos, PR URLs and the opening epoch ===" +# =========================================================================== +tdir="$TMPD/projects/sess"; mkdir -p "$tdir/abc/subagents" +tfile="$tdir/abc.jsonl" +gone="$clone/.claude/worktrees/removed-since" +jq -cn --arg cwd "$TMPD/wt-prs-clean" '{type:"user",timestamp:"2026-11-26T04:00:00.123Z",cwd:$cwd,message:{role:"user",content:"land it"}}' > "$tfile" +jq -cn --arg cmd "git -C \"$gone\" status && cd /nonexistent-root-dir && ls" --arg fp "$clone/README.md" \ + '{type:"assistant",timestamp:"2026-11-26T04:01:00Z",message:{content:[{type:"tool_use",name:"Bash",input:{command:$cmd}},{type:"tool_use",name:"Edit",input:{file_path:$fp}}]}}' >> "$tfile" +jq -cn '{type:"user",timestamp:"2026-11-26T04:02:00Z",message:{content:[{type:"tool_result",content:"opened https://github.com/acme/ops/pull/6190 ok"}]}}' >> "$tfile" +jq -cn '{type:"assistant",timestamp:"2026-11-26T04:03:00Z",message:{content:[{type:"text",text:"see https://github.com/acme/dots/pull/1051"}]}}' > "$tdir/abc/subagents/agent-1.jsonl" +want_epoch="$(jq -n '"2026-11-26T04:00:00Z" | fromdateiso8601')" +: > "$GQL_STUB_CALLS" +out="$(GQL_STUB_JSON="$gql_doc" gather --json --transcript "$tfile" 2>/dev/null)"; rc=$? +clone_p="$(cd "$clone" && pwd -P)" +chk "a gather with only --transcript exits 0" "$rc" +jqok "the opening epoch is the first timestamp, fraction dropped" "$out" ".transcript.started_at_epoch == $want_epoch and .since == $want_epoch" +jqok "a cwd, an Edit path and a removed worktree all resolve to one main checkout" "$out" ".transcript.repos == [\"$clone_p\"] and [.repos[].path] == [\"$clone_p\"]" +jqok "PR URLs come from the lead and subagent transcripts" "$out" '.transcript.prs == ["acme/ops#6190","acme/dots#1051"] and .transcript.subagent_transcripts == 1' +jqok "the transcript PRs are read live with the named ones" "$out" '[.named_prs.rows[].ref] == ["acme/ops#6190","acme/dots#1051"] and .named_prs.rows[1].state == "MERGED"' +chk "transcript PRs and --prs still cost one GraphQL call" "$([ "$(wc -l < "$GQL_STUB_CALLS" | tr -d ' ')" = 1 ]; echo $?)" +out="$(GQL_STUB_JSON="$gql_doc" gather --json --transcript "$tfile" --prs acme/ops#7 --since 1700000000 "$clone" 2>/dev/null)" +jqok "an explicit --since wins and a named repo is not gathered twice" "$out" '.since == 1700000000 and (.repos | length) == 1 and ([.named_prs.rows[].ref] | index("acme/ops#7")) != null' +sum="$(GQL_STUB_JSON="$gql_doc" gather --summary --transcript "$tfile" 2>/dev/null)" +chk_has "the summary names the transcript facts" "$sum" "transcript started_at_epoch=$want_epoch subagent_transcripts=1 repos=$clone_p prs=2" +out="$(gather --json --transcript "$TMPD/no-such.jsonl" "$clone" 2>&1)"; rc=$? +chk "a missing transcript file is refused" "$([ "$rc" -eq 64 ]; echo $?)" + echo if [ "$FAIL" -gt 0 ]; then echo "test-wrap-session: $PASS passed, $FAIL FAILED of $TOTAL" >&2; exit 1; fi echo "test-wrap-session: all $PASS passed" From 2a4ceb8bc0ef4443321878be6257da24887f84c4 Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 11:05:41 +0700 Subject: [PATCH 04/19] fix(wrap): transcript-named repos run no repo-configured program A repo the gather finds only through transcript text is read with core.fsmonitor and core.hooksPath neutralized through git's env config, which outranks every repo config file, and only when the current user owns the checkout. A planted fsmonitor hook fires on a plain gather (control) and never on a --transcript gather. ## How I verified it bash tests/test-wrap-session.sh -> test-wrap-session: all 133 passed --- lib/wrap/wrap-session.sh | 7 ++++++- tests/test-wrap-session.sh | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/wrap/wrap-session.sh b/lib/wrap/wrap-session.sh index 2767c648..3312d610 100644 --- a/lib/wrap/wrap-session.sh +++ b/lib/wrap/wrap-session.sh @@ -584,7 +584,8 @@ _session_transcript_json() { while [ -n "$d" ] && [ "$d" != "/" ] && [ ! -d "$d" ]; do d="$(dirname "$d")"; done [ -d "$d" ] && [ "$d" != "/" ] && [ "$d" != "$HOME" ] || continue main="$(_session_main_checkout "$d" 2>/dev/null)" || continue - [ -n "$main" ] && [ "$main" != "$HOME" ] && printf '%s\n' "$main" + # Only a checkout the current user owns; another user's repo is never gathered from transcript text. + [ -n "$main" ] && [ "$main" != "$HOME" ] && [ -O "$main" ] && printf '%s\n' "$main" done <&2; return 64; } + # Repos named by transcript text get read-only git with no repo-configured program: env config + # outranks every repo config file, so a planted core.fsmonitor or hooksPath never runs. + export GIT_CONFIG_COUNT=2 GIT_CONFIG_KEY_0=core.fsmonitor GIT_CONFIG_VALUE_0=false \ + GIT_CONFIG_KEY_1=core.hooksPath GIT_CONFIG_VALUE_1=/dev/null tjson="$(_session_transcript_json "$transcript")" [ -n "$tjson" ] || tjson='null' # A repo named on the command line is not gathered twice: compare symlink-free paths. diff --git a/tests/test-wrap-session.sh b/tests/test-wrap-session.sh index 5062569e..8231724e 100755 --- a/tests/test-wrap-session.sh +++ b/tests/test-wrap-session.sh @@ -398,6 +398,16 @@ out="$(GQL_STUB_JSON="$gql_doc" gather --json --transcript "$tfile" --prs acme/o jqok "an explicit --since wins and a named repo is not gathered twice" "$out" '.since == 1700000000 and (.repos | length) == 1 and ([.named_prs.rows[].ref] | index("acme/ops#7")) != null' sum="$(GQL_STUB_JSON="$gql_doc" gather --summary --transcript "$tfile" 2>/dev/null)" chk_has "the summary names the transcript facts" "$sum" "transcript started_at_epoch=$want_epoch subagent_transcripts=1 repos=$clone_p prs=2" +# A repo named only by transcript text runs no repo-configured program. The control run (the +# same repo named on the command line, no --transcript) proves the planted hook does fire. +printf '#!/bin/sh\ntouch "%s/fsmonitor-ran"\nexit 1\n' "$TMPD" > "$TMPD/fsmon.sh"; chmod +x "$TMPD/fsmon.sh" +git -C "$clone" config core.fsmonitor "$TMPD/fsmon.sh" +gather --json "$clone" >/dev/null 2>&1 +chk "control: a planted core.fsmonitor fires on a plain gather" "$([ -e "$TMPD/fsmonitor-ran" ]; echo $?)" +rm -f "$TMPD/fsmonitor-ran" +GQL_STUB_JSON="$gql_doc" gather --json --transcript "$tfile" >/dev/null 2>&1 +chk "a planted core.fsmonitor never fires for a transcript-named repo" "$([ ! -e "$TMPD/fsmonitor-ran" ]; echo $?)" +git -C "$clone" config --unset core.fsmonitor out="$(gather --json --transcript "$TMPD/no-such.jsonl" "$clone" 2>&1)"; rc=$? chk "a missing transcript file is refused" "$([ "$rc" -eq 64 ]; echo $?)" From 11d87a9168a858d19fc1f5259fd4b9bfefaf5144 Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 11:18:30 +0700 Subject: [PATCH 05/19] feat(wrap): tag acted vs mentioned PRs and keep the miner beside the gather Replay round 2 cut lead calls to a median of 6.5 but lost quality: reports credited the session with PRs it only quoted, and found fewer distill candidates without the miner. The transcript read now tags each PR: acted when a PR-writing command (gh pr create, merge, ready, close; wrap land, ship, merge) or its output names it, mentioned otherwise. Shipped credits only acted PRs and the ones the miner confirms. commands/wrap.md dispatches the read-only miner in the same turn as the gather, and the needs-you walk drops an action a later reply shows done. ## How I verified it bash tests/test-wrap-session.sh -> test-wrap-session: all 134 passed --- commands/wrap.md | 10 ++++++---- lib/wrap/wrap-session.sh | 30 ++++++++++++++++++++++++++---- tests/test-wrap-session.sh | 10 ++++++---- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/commands/wrap.md b/commands/wrap.md index d15f3adb..546c970c 100644 --- a/commands/wrap.md +++ b/commands/wrap.md @@ -12,7 +12,7 @@ Run after `/kit:ship`, at session end, or when the operator asks to land work. N The distill half is the candidate scan, both seams, steps 7a-7c, and the drain. It is on unless the operator root config sets `wrap.distill = false`; `harvest` hands it to the harvest sweep only when `/sweep/installed` exists and `harvest.enable` is true. With distill off, skip those distill steps by name and report `SKIPPED: distill off`. The retro is landing, not distill, and still runs when its ledger condition is met. Harvest mode reports `SKIPPED: distill runs in the harvest sweep`; in phase 1 the sweep reports candidates and builds none. Read `harvest_sweep.py --status` for the newest report. When the knob resolves as true but the marker is absent, the FYI row says `not installed on this host`. An explicit one-shot distill means the sweep will also see this session. -**Wrapping another session.** Never scan the wrapper's empty context. Use the transcript path the operator or the dispatch gives; when you have only a name, resolve it with `bin/session recall --name`. Then make ONE digest call: `bin/session recall --replies `, every turn's prompt and final reply. That digest is the only transcript read. It names the repos, the PRs, the board rows, and the operator's open asks. Only when the digest cannot name the landing facts (a turn ended with no final reply), list worker transcripts with `bin/session recall --subagents` and dispatch one read-only Sonnet miner; use only its candidate list and landing facts. The lead never reads a transcript into its own context. +**Wrapping another session.** Never scan the wrapper's empty context. Use the transcript path the operator or the dispatch gives; when you have only a name, resolve it with `bin/session recall --name`. Then make ONE digest call: `bin/session recall --replies `, every turn's prompt and final reply. In the SAME turn as the start gather, dispatch one read-only Sonnet miner over the transcript and its worker transcripts (list them with `bin/session recall --subagents` inside the miner's brief, not as a lead call). The miner returns only: the distill candidates (the candidate scan below, each with its evidence), the landing facts (PRs this session opened or merged, board rows and items it changed, work it handed to another agent), and the owner actions still open at the end. Use only its lists and the digest. The lead never reads a transcript into its own context. ## Start gather @@ -23,13 +23,13 @@ bin/wrap session --summary [--transcript ] --mark-dir "$scratch" [-- ``` - `--transcript` (always, when wrapping another session; a self-wrap whose transcript path is unknown passes its repos and `--since`) makes the script read the target transcript and its subagent transcripts, so you never do. It adds every repo the session worked in (each cwd, Edit or Write path, `git -C` or `cd` target, resolved to its main checkout), every GitHub PR URL, and the session start epoch (the first timestamp, the writer-check threshold unless you pass `--since`). Never look for repo paths, PR numbers or the start time yourself. Name a `` or a `--prs` ref only when the digest names one the `transcript` line lacks. -- `--prs` and the transcript's PRs are read live, in one batched GitHub call: state, merged, mergedAt, merge commit, its check state, head branch. A PR's state in the report comes from this read, never from the transcript. A named PR whose repo has no local checkout needs none: its live row is the fact. +- `--prs` and the transcript's PRs are read live, in one batched GitHub call: state, merged, mergedAt, merge commit, its check state, head branch. A PR's state in the report comes from this read, never from the transcript. A named PR whose repo has no local checkout needs none: its live row is the fact. Each transcript PR row carries `session=acted` (a PR-writing command named it: `gh pr create`, `merge`, `wrap land`) or `session=mentioned` (only quoted). `Shipped` credits the session only with `acted` rows and the PRs the miner says it opened or merged; a `mentioned` PR is context, never this session's work. - `--mark-dir` is step 0's check for activity before the wrap, taken per repo before the repo is read. It records each writer mark as `writers_mark="$scratch/writers-.json"`, the repo's absolute path without its leading slash and with `/` as `-`; the `writers` line prints the path. Its `foreign_activity` (an `index.lock`, or a reflog row newer than the session start in any worktree except the session's own, the main checkout included) stops the repo exactly as the landing pass describes. The `--transcript` start epoch is the target session's real start; without a transcript, pass `--since` with the time this wrap started. - `--summary` prints every field this command reads, one fact per line. Read it once. `--json` prints the same gather as one `wrap-session/1` document for a tool; never re-read either with `jq`. The gather holds config knobs, activity-log state, the named PRs, and per repo the checkout, dirty files, worktrees, writer facts, active board rows, handoffs, own open PRs with check totals and gates, recent merge deploy state, and the sweep report. Treat it as facts, not as proof of intent. Rows this session did not touch stay untouched. -**What the gather replaces.** Run none of these when the gather covers the fact: `git status`, `git log`, `git for-each-ref` or any other git read; `wrap scan` or a `wrap apply` dry run (the summary's `sweep` lines carry its verdicts); a grep, `rg`, `jq`, Glob or Read over the transcript or to find a repo; a re-read of the gather; `gh pr view` or `gh run list` one PR at a time (put the PR in `--prs`); a `--help` call. The target is 10 lead calls per wrap: this file, the digest, the gather, the step 7b lookups, one `flick-7b`, and only the writes a decision needs. +**What the gather replaces.** Run none of these when the gather covers the fact: `git status`, `git log`, `git for-each-ref` or any other git read; `wrap scan` or a `wrap apply` dry run (the summary's `sweep` lines carry its verdicts); a grep, `rg`, `jq`, Glob or Read over the transcript or to find a repo; a re-read of the gather; `gh pr view` or `gh run list` one PR at a time (put the PR in `--prs`); a `--help` call. The target is 10 lead calls per wrap: this file, the digest, the gather with the miner beside it, the step 7b lookups, one `flick-7b`, and only the writes a decision needs. **Handed-off work.** A change the session handed to another agent or bot ("X will open the PR") has no ref in the digest. Find it with one `gh pr list --repo --state all --search ""` and state only what that live read shows. Never call a PR or a handed-off change pending, open, or merged from the transcript alone. @@ -80,7 +80,9 @@ The after seam invokes the configured `wrap.after` skill after landing. Empty is When any write step ran, run one final read-only gather over the same repos before drafting: `bin/wrap session --summary ...`. `Left alone` uses that final gather, never memory or the start snapshot. When no write ran (a dry run, or nothing to land), the start gather is the final state; do not gather again. -**Needs-you check, before writing `NOTHING`.** Walk the digest's replies, newest first, and list every owner action they name: an ask to the operator, a blocker, a lettered `a.` `b.` item, "needs Han" or "needs you", an approval, and a merge, close, or click left to the owner. Each one is either proven done by a gather row or a live read, or it goes under `Needs you`. When unsure, list it with `check`: `a. RUN check . .` Write `NOTHING` only when this walk found no open item, never because the gather shows nothing. Draft the skim-first report, write it to scratch. Run the lint before printing: `bash lib/wrap/report-lint.sh `. Fix or do what the lint names, then re-run. The shape is: +**Needs-you check, before writing `NOTHING`.** Walk the digest's replies and the miner's open owner actions, newest first. List every owner action they name: an ask to the operator, a blocker, a lettered `a.` `b.` item, "needs Han" or "needs you", an approval, and a merge, close, or click left to the owner. An action a later reply, the miner, or a gather row shows done is closed; leave it out. Every other one goes under `Needs you`. When the newest mention leaves it open but you cannot prove it still is, list it with `check`: `a. RUN check . .` Write `NOTHING` only when this walk found no open item, never because the gather shows nothing. + +Draft the skim-first report, write it to scratch. Run the lint before printing: `bash lib/wrap/report-lint.sh `. Fix or do what the lint names, then re-run. The shape is: ```markdown ## Wrap: diff --git a/lib/wrap/wrap-session.sh b/lib/wrap/wrap-session.sh index 3312d610..241b7c10 100644 --- a/lib/wrap/wrap-session.sh +++ b/lib/wrap/wrap-session.sh @@ -563,7 +563,7 @@ _session_config_json() { # cwd, each Edit/Write path, each `git -C` or `cd` target). A path that no longer exists walks up to # its nearest existing parent, so a removed worktree still names its repo. _session_transcript_json() { - local t="$1" start prs paths p d main repos_json + local t="$1" start prs acted paths p d main repos_json local -a tfiles=("$t") for p in "${t%.jsonl}"/subagents/*.jsonl; do [ -f "$p" ] && tfiles+=("$p"); done start="$(jq -r 'select(.timestamp != null) | .timestamp' "$t" 2>/dev/null | head -n 1 \ @@ -572,6 +572,23 @@ _session_transcript_json() { prs="$(cat "${tfiles[@]}" 2>/dev/null | grep -Eo 'https://github\.com/[A-Za-z0-9][A-Za-z0-9-]*/[A-Za-z0-9_.-]+/pull/[0-9]+' \ | sed -E 's#^https://github\.com/([^/]+)/([^/]+)/pull/([0-9]+)$#\1/\2\#\3#' | awk '!seen[$0]++' | head -n 50 | _session_lines_json)" [ -n "$prs" ] || prs='[]' + # The PRs this session acted on: a URL in a PR-writing command or its output (gh pr create, merge, + # ready, close; wrap land, ship, merge), or `gh pr merge|ready|close --repo `. + # Every other URL was only mentioned, and a report never credits the session with it. + acted="$(jq -rn ' + [inputs | .message.content[]? | select(type == "object")] as $b + | [$b[] | select(.type == "tool_use" and .name == "Bash") + | select((.input.command // "") | test("gh +pr +(create|merge|ready|close)|wrap +(land|ship|merge)"))] as $acts + | ($acts | map(.id)) as $ids + | ($acts[] | .input.command), + ($b[] | select(.type == "tool_result" and (.tool_use_id as $t | $ids | index($t))) | .content | tostring), + ($acts[] | .input.command + | ([scan("(?:--repo|-R)[ =]+([A-Za-z0-9][A-Za-z0-9-]*/[A-Za-z0-9_.-]+)")[0]] | first) as $r + | select($r != null) | scan("gh +pr +(?:merge|ready|close) +([0-9]+)")[0] | "https://github.com/\($r)/pull/\(.)") + ' "${tfiles[@]}" 2>/dev/null | grep -Eo 'https://github\.com/[A-Za-z0-9][A-Za-z0-9-]*/[A-Za-z0-9_.-]+/pull/[0-9]+' \ + | sed -E 's#^https://github\.com/([^/]+)/([^/]+)/pull/([0-9]+)$#\1/\2\#\3#' | awk '!seen[$0]++' | _session_lines_json)" + [ -n "$acted" ] || acted='[]' + prs="$(jq -cn --argjson a "$acted" --argjson p "$prs" '$a + [$p[] | select(. as $x | $a | index($x) | not)]')" paths="$(jq -r ' (select(.cwd != null) | .cwd), (.message.content[]? | select(.type == "tool_use") | .input @@ -593,7 +610,8 @@ EOF_SESSION_TPATHS [ -n "$repos_json" ] || repos_json='[]' jq -cn --arg path "$t" --argjson start "$start" --argjson prs "$prs" --argjson repos "$repos_json" \ --argjson subagents "$(( ${#tfiles[@]} - 1 ))" \ - '{path:$path,started_at_epoch:$start,subagent_transcripts:$subagents,prs:$prs,repos:$repos}' + --argjson acted "$acted" \ + '{path:$path,started_at_epoch:$start,subagent_transcripts:$subagents,prs:$prs,acted_prs:$acted,repos:$repos}' } # _session_pr_refs ... -- every PR ref as `owner/name#n`, one per line, deduplicated. @@ -670,13 +688,13 @@ _session_summary_text() { "wrap-session/1 generated_at=\(.generated_at) epoch=\(.generated_at_epoch) repos=\(.summary.repos) open_own_prs=\(.summary.open_own_prs) pending_prs=\(.summary.pending_prs) named_prs=\(.summary.named_prs) foreign_activity_repos=\(.summary.foreign_activity_repos)", "config " + (.config | to_entries | map("\(.key)=\(.value | v)") | join(" ")), (.transcript // null | select(. != null) | - "transcript started_at_epoch=\(.started_at_epoch | v) subagent_transcripts=\(.subagent_transcripts) repos=\(.repos | join(",") | if . == "" then "-" else . end) prs=\(.prs | length)"), + "transcript started_at_epoch=\(.started_at_epoch | v) subagent_transcripts=\(.subagent_transcripts) repos=\(.repos | join(",") | if . == "" then "-" else . end) prs=\(.prs | length) acted_prs=\(.acted_prs | join(",") | if . == "" then "-" else . end)"), "writer_since=\(.since | v)", "activity_log configured=\(.activity_log.configured) target=\(.activity_log.resolved | v) writable=\(.activity_log.writable) error=\(.activity_log.error | v)", (.named_prs // null | select(. != null) | "named_prs read_at=\(.read_at) gh=\(.gh_state) error=\(.error | v)", (.rows[] | if .error then " pr \(.ref) ERROR \(.error)" - else " pr \(.ref) state=\(.state) merged=\(.merged) merged_at=\(.merged_at | v) merge=\(.merge_sha | sha) merge_checks=\(.merge_checks | v) head=\(.head_branch | v) draft=\(.draft) author=\(.author | v) \"\(.title)\"" end)), + else " pr \(.ref)\(if .session then " session=\(.session)" else "" end) state=\(.state) merged=\(.merged) merged_at=\(.merged_at | v) merge=\(.merge_sha | sha) merge_checks=\(.merge_checks | v) head=\(.head_branch | v) draft=\(.draft) author=\(.author | v) \"\(.title)\"" end)), (.repos[] | if .is_repo != true then "repo \(.path) NOT A REPO: \(.error | v)" else "repo \(.path) slug=\(.github_slug | v) default=\(.default_branch | v) branch=\(.checkout.branch | v) ahead=\(.checkout.ahead | v) behind=\(.checkout.behind | v) dirty=\(.checkout.dirty_files | length) index_lock=\(.checkout.index_lock.present) fetch=\"\(.fetch_error | v)\"", @@ -886,6 +904,10 @@ EOF_SESSION_TREPOS rm -f "$tmp" [ -n "$refs" ] && named="$(_session_named_prs_json "$refs")" [ -n "$named" ] || named='null' + if [ "$named" != null ] && [ "$tjson" != null ]; then + named="$(printf '%s' "$named" | jq -c --argjson t "$tjson" '.rows |= map(.ref as $r + | . + {session:(if ($t.acted_prs | index($r)) then "acted" elif ($t.prs | index($r)) then "mentioned" else "named" end)})')" + fi config="$(_session_config_json "$follow")" activity="$(_session_activity_json)" end=$(( $(date +%s) * 1000 )); duration=$(( end - start )) diff --git a/tests/test-wrap-session.sh b/tests/test-wrap-session.sh index 8231724e..1761b0ee 100755 --- a/tests/test-wrap-session.sh +++ b/tests/test-wrap-session.sh @@ -382,7 +382,8 @@ gone="$clone/.claude/worktrees/removed-since" jq -cn --arg cwd "$TMPD/wt-prs-clean" '{type:"user",timestamp:"2026-11-26T04:00:00.123Z",cwd:$cwd,message:{role:"user",content:"land it"}}' > "$tfile" jq -cn --arg cmd "git -C \"$gone\" status && cd /nonexistent-root-dir && ls" --arg fp "$clone/README.md" \ '{type:"assistant",timestamp:"2026-11-26T04:01:00Z",message:{content:[{type:"tool_use",name:"Bash",input:{command:$cmd}},{type:"tool_use",name:"Edit",input:{file_path:$fp}}]}}' >> "$tfile" -jq -cn '{type:"user",timestamp:"2026-11-26T04:02:00Z",message:{content:[{type:"tool_result",content:"opened https://github.com/acme/ops/pull/6190 ok"}]}}' >> "$tfile" +jq -cn '{type:"assistant",timestamp:"2026-11-26T04:01:30Z",message:{content:[{type:"tool_use",id:"tu-create",name:"Bash",input:{command:"gh pr create --fill"}},{type:"tool_use",id:"tu-merge",name:"Bash",input:{command:"gh pr merge 7 --repo acme/ops --squash"}}]}}' >> "$tfile" +jq -cn '{type:"user",timestamp:"2026-11-26T04:02:00Z",message:{content:[{type:"tool_result",tool_use_id:"tu-create",content:"https://github.com/acme/ops/pull/6190"}]}}' >> "$tfile" jq -cn '{type:"assistant",timestamp:"2026-11-26T04:03:00Z",message:{content:[{type:"text",text:"see https://github.com/acme/dots/pull/1051"}]}}' > "$tdir/abc/subagents/agent-1.jsonl" want_epoch="$(jq -n '"2026-11-26T04:00:00Z" | fromdateiso8601')" : > "$GQL_STUB_CALLS" @@ -391,13 +392,14 @@ clone_p="$(cd "$clone" && pwd -P)" chk "a gather with only --transcript exits 0" "$rc" jqok "the opening epoch is the first timestamp, fraction dropped" "$out" ".transcript.started_at_epoch == $want_epoch and .since == $want_epoch" jqok "a cwd, an Edit path and a removed worktree all resolve to one main checkout" "$out" ".transcript.repos == [\"$clone_p\"] and [.repos[].path] == [\"$clone_p\"]" -jqok "PR URLs come from the lead and subagent transcripts" "$out" '.transcript.prs == ["acme/ops#6190","acme/dots#1051"] and .transcript.subagent_transcripts == 1' -jqok "the transcript PRs are read live with the named ones" "$out" '[.named_prs.rows[].ref] == ["acme/ops#6190","acme/dots#1051"] and .named_prs.rows[1].state == "MERGED"' +jqok "PR URLs come from the lead and subagent transcripts" "$out" '.transcript.prs == ["acme/ops#6190","acme/ops#7","acme/dots#1051"] and .transcript.subagent_transcripts == 1' +jqok "a PR a create or merge command names is acted, a quoted URL only mentioned" "$out" '.transcript.acted_prs == ["acme/ops#6190","acme/ops#7"] and ([.named_prs.rows[] | {(.ref): .session}] | add) == {"acme/ops#6190":"acted","acme/ops#7":"acted","acme/dots#1051":"mentioned"}' +jqok "the transcript PRs are read live with the named ones" "$out" '[.named_prs.rows[].ref] == ["acme/ops#6190","acme/ops#7","acme/dots#1051"] and .named_prs.rows[2].state == "MERGED"' chk "transcript PRs and --prs still cost one GraphQL call" "$([ "$(wc -l < "$GQL_STUB_CALLS" | tr -d ' ')" = 1 ]; echo $?)" out="$(GQL_STUB_JSON="$gql_doc" gather --json --transcript "$tfile" --prs acme/ops#7 --since 1700000000 "$clone" 2>/dev/null)" jqok "an explicit --since wins and a named repo is not gathered twice" "$out" '.since == 1700000000 and (.repos | length) == 1 and ([.named_prs.rows[].ref] | index("acme/ops#7")) != null' sum="$(GQL_STUB_JSON="$gql_doc" gather --summary --transcript "$tfile" 2>/dev/null)" -chk_has "the summary names the transcript facts" "$sum" "transcript started_at_epoch=$want_epoch subagent_transcripts=1 repos=$clone_p prs=2" +chk_has "the summary names the transcript facts" "$sum" "transcript started_at_epoch=$want_epoch subagent_transcripts=1 repos=$clone_p prs=3 acted_prs=acme/ops#6190,acme/ops#7" # A repo named only by transcript text runs no repo-configured program. The control run (the # same repo named on the command line, no --transcript) proves the planted hook does fire. printf '#!/bin/sh\ntouch "%s/fsmonitor-ran"\nexit 1\n' "$TMPD" > "$TMPD/fsmon.sh"; chmod +x "$TMPD/fsmon.sh" From 64b6e236e29d17dc0c877fff4a4128122e25c6db Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 11:33:04 +0700 Subject: [PATCH 06/19] fix(wrap): clear the CI lints on the one-call gather - Mark the four new PR merge-state lines merged-ok (report facts, never a deletion proof) and pin the count at 9 in test-shared-lookups. - commands/wrap.md names `session recall --tail` again for an id prefix, which the recall suite requires. - test-wrap-session.sh: SC2319 fixed across the file (`[ x ] && echo 0 || echo 1`), so the pr-shape shellcheck passes on the touched suite. ## How I verified it bash tests/test-wrap-session.sh -> test-wrap-session: all 134 passed bash tests/test-shared-lookups.sh -> test-shared-lookups: all 15 passed bash tests/test-session-recall.sh -> PASS: session-recall shellcheck -S warning tests/test-wrap-session.sh -> exit 0 --- commands/wrap.md | 2 +- lib/wrap/wrap-session.sh | 8 +++---- tests/test-shared-lookups.sh | 2 +- tests/test-wrap-session.sh | 42 ++++++++++++++++++------------------ 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/commands/wrap.md b/commands/wrap.md index 546c970c..afd0ddf4 100644 --- a/commands/wrap.md +++ b/commands/wrap.md @@ -12,7 +12,7 @@ Run after `/kit:ship`, at session end, or when the operator asks to land work. N The distill half is the candidate scan, both seams, steps 7a-7c, and the drain. It is on unless the operator root config sets `wrap.distill = false`; `harvest` hands it to the harvest sweep only when `/sweep/installed` exists and `harvest.enable` is true. With distill off, skip those distill steps by name and report `SKIPPED: distill off`. The retro is landing, not distill, and still runs when its ledger condition is met. Harvest mode reports `SKIPPED: distill runs in the harvest sweep`; in phase 1 the sweep reports candidates and builds none. Read `harvest_sweep.py --status` for the newest report. When the knob resolves as true but the marker is absent, the FYI row says `not installed on this host`. An explicit one-shot distill means the sweep will also see this session. -**Wrapping another session.** Never scan the wrapper's empty context. Use the transcript path the operator or the dispatch gives; when you have only a name, resolve it with `bin/session recall --name`. Then make ONE digest call: `bin/session recall --replies `, every turn's prompt and final reply. In the SAME turn as the start gather, dispatch one read-only Sonnet miner over the transcript and its worker transcripts (list them with `bin/session recall --subagents` inside the miner's brief, not as a lead call). The miner returns only: the distill candidates (the candidate scan below, each with its evidence), the landing facts (PRs this session opened or merged, board rows and items it changed, work it handed to another agent), and the owner actions still open at the end. Use only its lists and the digest. The lead never reads a transcript into its own context. +**Wrapping another session.** Never scan the wrapper's empty context. Use the transcript path the operator or the dispatch gives; when you have only a name, resolve it with `bin/session recall --name`; when you have only an id prefix, confirm it with `bin/session recall --tail `. Then make ONE digest call: `bin/session recall --replies `, every turn's prompt and final reply. In the SAME turn as the start gather, dispatch one read-only Sonnet miner over the transcript and its worker transcripts (list them with `bin/session recall --subagents` inside the miner's brief, not as a lead call). The miner returns only: the distill candidates (the candidate scan below, each with its evidence), the landing facts (PRs this session opened or merged, board rows and items it changed, work it handed to another agent), and the owner actions still open at the end. Use only its lists and the digest. The lead never reads a transcript into its own context. ## Start gather diff --git a/lib/wrap/wrap-session.sh b/lib/wrap/wrap-session.sh index 241b7c10..09250611 100644 --- a/lib/wrap/wrap-session.sh +++ b/lib/wrap/wrap-session.sh @@ -654,7 +654,7 @@ _session_named_prs_json() { END { printf "query {" for (i = 0; i < n; i++) { split(order[i], on, "/"); printf " r%d: repository(owner: \"%s\", name: \"%s\") {%s }", i, on[1], on[2], prs[i] } - printf " } fragment F on PullRequest { number title url state merged mergedAt mergeCommit { oid statusCheckRollup { state } } headRefName baseRefName isDraft author { login } }\n" + printf " } fragment F on PullRequest { number title url state merged mergedAt mergeCommit { oid statusCheckRollup { state } } headRefName baseRefName isDraft author { login } }\n" # merged-ok: a live PR merge state read as a report fact, never a deletion proof }')" # gh exits non-zero on a partial GraphQL error but still prints the data, so stdout is read either way. out="$(gh api graphql -f query="$query" 2>/dev/null)" @@ -671,7 +671,7 @@ _session_named_prs_json() { // (if ($doc.data // null) == null then "graphql read failed" else "not found" end))} else {ref:$ref, number:$pr.number, title:$pr.title, url:$pr.url, state:$pr.state, merged:$pr.merged, - merged_at:$pr.mergedAt, merge_sha:($pr.mergeCommit.oid // null), + merged_at:$pr.mergedAt, merge_sha:($pr.mergeCommit.oid // null), # merged-ok: a live PR merge state read as a report fact, never a deletion proof merge_checks:($pr.mergeCommit.statusCheckRollup.state // null), head_branch:$pr.headRefName, base_branch:$pr.baseRefName, draft:$pr.isDraft, author:($pr.author.login // null), error:null} end' | jq -s .)" @@ -694,7 +694,7 @@ _session_summary_text() { (.named_prs // null | select(. != null) | "named_prs read_at=\(.read_at) gh=\(.gh_state) error=\(.error | v)", (.rows[] | if .error then " pr \(.ref) ERROR \(.error)" - else " pr \(.ref)\(if .session then " session=\(.session)" else "" end) state=\(.state) merged=\(.merged) merged_at=\(.merged_at | v) merge=\(.merge_sha | sha) merge_checks=\(.merge_checks | v) head=\(.head_branch | v) draft=\(.draft) author=\(.author | v) \"\(.title)\"" end)), + else " pr \(.ref)\(if .session then " session=\(.session)" else "" end) state=\(.state) merged=\(.merged) merged_at=\(.merged_at | v) merge=\(.merge_sha | sha) merge_checks=\(.merge_checks | v) head=\(.head_branch | v) draft=\(.draft) author=\(.author | v) \"\(.title)\"" end)), # merged-ok: a live PR merge state printed as a report fact, never a deletion proof (.repos[] | if .is_repo != true then "repo \(.path) NOT A REPO: \(.error | v)" else "repo \(.path) slug=\(.github_slug | v) default=\(.default_branch | v) branch=\(.checkout.branch | v) ahead=\(.checkout.ahead | v) behind=\(.checkout.behind | v) dirty=\(.checkout.dirty_files | length) index_lock=\(.checkout.index_lock.present) fetch=\"\(.fetch_error | v)\"", @@ -714,7 +714,7 @@ _session_summary_text() { ((.checks.latest // [])[] | select(((.conclusion // "") | ascii_upcase) as $c | $c != "SUCCESS" and $c != "SKIPPED" and $c != "NEUTRAL") | " check \(.name) \(.status // "-") \(.conclusion // "pending")")), (.pull_requests as $p | $p.merged_recent[]? | . as $m | ([$p.deploys[]? | select(.pr == $m.number)][0] // {}) as $d - | " merged #\(.number) at=\(.mergedAt | v) merge=\(.merge_sha | sha) deploy=\($d.state // "-") head=\(.headRefName | v) \"\(.title // "")\""), + | " merged #\(.number) at=\(.mergedAt | v) merge=\(.merge_sha | sha) deploy=\($d.state // "-") head=\(.headRefName | v) \"\(.title // "")\""), # merged-ok: a live PR merge state printed as a report fact, never a deletion proof (.sweep | if .format == "json" then (.document.repos[]? | " sweep " + ((.rows // []) | group_by(.verdict) | map("\(.[0].verdict)=\(length)") | join(" ") | if . == "" then "rows=0" else . end) + (if .error then " error=\"\(.error)\"" else "" end), diff --git a/tests/test-shared-lookups.sh b/tests/test-shared-lookups.sh index b43cdbd3..3055d5e5 100644 --- a/tests/test-shared-lookups.sh +++ b/tests/test-shared-lookups.sh @@ -120,7 +120,7 @@ merged-ok lib/wrap/wrap-land.sh 2 merged-ok lib/wrap/wrap-merge.sh 6 merged-ok lib/wrap/wrap-rebase.sh 1 merged-ok lib/wrap/wrap-scan.sh 2 -merged-ok lib/wrap/wrap-session.sh 5 +merged-ok lib/wrap/wrap-session.sh 9 spec-active-ok hooks/ship-gate.sh 3 spec-active-ok lib/gate/gate-ledger.sh 3 spec-active-ok lib/gate/proof-ledger.sh 3 diff --git a/tests/test-wrap-session.sh b/tests/test-wrap-session.sh index 1761b0ee..e78f72ed 100755 --- a/tests/test-wrap-session.sh +++ b/tests/test-wrap-session.sh @@ -12,7 +12,7 @@ jqok() { printf '%s' "$2" | jq -e "$3" >/dev/null 2>&1; chk "$1" "$?"; } echo "=== usage and invalid repos ===" # =========================================================================== out="$("$WRAP" session 2>&1)"; rc=$? -chk "session with no arguments exits 64" "$([ "$rc" -eq 64 ]; echo $?)" +chk "session with no arguments exits 64" "$([ "$rc" -eq 64 ] && echo 0 || echo 1)" chk_has "session usage names --json" "$out" "session --json" out="$("$WRAP" session --json "$TMPD/no-such-repo" 2>/dev/null)"; rc=$? chk "an invalid repo still exits 0 with JSON" "$rc" @@ -53,7 +53,7 @@ jqok "handoff state is structured" "$out" '(.repos[0].handoffs.lines|type) == "a jqok "the own open PR carries its check totals and gate" "$out" '.repos[0].pull_requests.open_own[0].number == 7 and .repos[0].pull_requests.open_own[0].checks.total == 2 and .repos[0].pull_requests.open_own[0].gate == "OK"' jqok "the sweep JSON seam is used unchanged" "$out" '.repos[0].sweep.format == "json" and .repos[0].sweep.document.schema == "wrap-sweep/1" and .repos[0].sweep.document.summary.would_remove == 3' jqok "the top summary aggregates PRs and sweep rows" "$out" '.summary.repos == 1 and .summary.open_own_prs == 1 and .summary.sweep_would_remove == 3 and .summary.sweep_rows == 6' -chk "the gather changes neither checkout state nor worktree inventory" "$([ "$before" = "$after" ]; echo $?)" +chk "the gather changes neither checkout state nor worktree inventory" "$([ "$before" = "$after" ] && echo 0 || echo 1)" chk_no "the gather does not print human lines on stdout" "$out" "SKIP worktree" # =========================================================================== @@ -103,9 +103,9 @@ jqok "with wrap sweep present the gather reads its JSON (run with --no-fetch)" " nosweep="$(mktemp "${TMPDIR:-/tmp}/kit.XXXXXX")" || exit 1; printf '#!/bin/sh\nexit 64\n' > "$nosweep"; chmod +x "$nosweep" out_ns="$(WRAP_SESSION_WRAP_BIN="$nosweep" "$WRAP" session --json "$clone" 2>/dev/null)"; rm -f "$nosweep" jqok "without wrap sweep the row falls back to read-only inventory text" "$out_ns" '.repos[0].sweep.format == "text" and .repos[0].sweep.document == null and (.repos[0].sweep.text|type) == "string" and (.repos[0].sweep.text | contains("read-only; no fetch"))' -chk "the fallback gather changes no ref" "$([ "$refs_before" = "$refs_after" ]; echo $?)" -chk "the fallback gather neither creates nor removes FETCH_HEAD" "$([ "$fh_before" = "$fh_after" ]; echo $?)" -chk "the fallback gather does not refresh the index" "$([ "$index_before" = "$index_after" ]; echo $?)" +chk "the fallback gather changes no ref" "$([ "$refs_before" = "$refs_after" ] && echo 0 || echo 1)" +chk "the fallback gather neither creates nor removes FETCH_HEAD" "$([ "$fh_before" = "$fh_after" ] && echo 0 || echo 1)" +chk "the fallback gather does not refresh the index" "$([ "$index_before" = "$index_after" ] && echo 0 || echo 1)" out="$(WRAP_SESSION_WRAP_BIN="$fake" GH_STUB_UNAUTH=1 "$WRAP" session --json "$clone" 2>/dev/null)"; rc=$? chk "an unauthenticated gh still exits 0" "$rc" jqok "gh degradation is a field, not a failure" "$out" '.repos[0].pull_requests.gh_state == "unauthenticated" and .repos[0].pull_requests.open_own == []' @@ -142,7 +142,7 @@ jqok "writers reports the lock on its own worktree row" "$out" '([.worktrees[] | chk "writers text fallback exits 0" "$trc" json_rows="$(printf '%s' "$out" | jq '.worktrees | length' 2>/dev/null)" text_rows="$(printf '%s\n' "$text" | grep -c '^writer path=')" -chk "writers text fallback carries every worktree row" "$([ "$json_rows" = "$text_rows" ]; echo $?)" +chk "writers text fallback carries every worktree row" "$([ "$json_rows" = "$text_rows" ] && echo 0 || echo 1)" chk_has "writers text fallback carries the lock fact" "$text" "index_lock_present=true" chk_has "writers text fallback carries the per-row reflog fact" "$text" "reflog_newer_than_since=false" @@ -217,14 +217,14 @@ mkdir -p "$kitcp" cp -R "$KIT_DIR/lib" "$KIT_DIR/bin" "$kitcp/" rm -f "$kitcp/lib/board/states.tsv" out="$(WRAP_SESSION_WRAP_BIN="$fake" "$kitcp/bin/wrap" session --json "$clone" 2>"$TMPD/states.err")"; rc=$? -chk "a missing states.tsv makes session exit non-zero" "$([ "$rc" -ne 0 ]; echo $?)" +chk "a missing states.tsv makes session exit non-zero" "$([ "$rc" -ne 0 ] && echo 0 || echo 1)" chk_has "a missing states.tsv is named on stderr" "$(cat "$TMPD/states.err")" "lib/board/states.tsv" -chk "a missing states.tsv prints no JSON document" "$([ -z "$out" ]; echo $?)" +chk "a missing states.tsv prints no JSON document" "$([ -z "$out" ] && echo 0 || echo 1)" printf '# every state was commented out\n' > "$kitcp/lib/board/states.tsv" out="$(WRAP_SESSION_WRAP_BIN="$fake" "$kitcp/bin/wrap" session --json "$clone" 2>"$TMPD/states.err")"; rc=$? -chk "a comment-only states.tsv makes session exit non-zero" "$([ "$rc" -ne 0 ]; echo $?)" +chk "a comment-only states.tsv makes session exit non-zero" "$([ "$rc" -ne 0 ] && echo 0 || echo 1)" chk_has "a comment-only states.tsv is named on stderr" "$(cat "$TMPD/states.err")" "lib/board/states.tsv" -chk "a comment-only states.tsv prints no JSON document" "$([ -z "$out" ]; echo $?)" +chk "a comment-only states.tsv prints no JSON document" "$([ -z "$out" ] && echo 0 || echo 1)" printf 'a.b\tactive\t-\nexecuting\tactive\tshipped\nshipped\tterminal\t-\n' > "$kitcp/lib/board/states.tsv" cat > "$clone/_meta/BACKLOG.md" <<'BOARD' | ID | Title | State | @@ -280,7 +280,7 @@ echo "=== --prs: every named PR, one batched GraphQL call, live state ===" : > "$GQL_STUB_CALLS" out="$(GQL_STUB_JSON="$gql_doc" GQL_STUB_RC=1 gather --json --prs "acme/ops#6190,acme/ops#7" --prs https://github.com/acme/dots/pull/1051 --prs acme/ops#999 --prs acme/ops#7 "$clone" 2>/dev/null)"; rc=$? chk "a gather with --prs exits 0 even when gh exits 1 on a partial error" "$rc" -chk "four distinct refs across two repos cost exactly one GraphQL call" "$([ "$(wc -l < "$GQL_STUB_CALLS" | tr -d ' ')" = 1 ]; echo $?)" +chk "four distinct refs across two repos cost exactly one GraphQL call" "$([ "$(wc -l < "$GQL_STUB_CALLS" | tr -d ' ')" = 1 ] && echo 0 || echo 1)" q="$(cat "$GQL_STUB_CALLS")" chk_has "the query aliases the first repo" "$q" 'r0: repository(owner: "acme", name: "ops")' chk_has "the query aliases the second repo" "$q" 'r1: repository(owner: "acme", name: "dots")' @@ -300,11 +300,11 @@ jqok "a failed read keeps the ref as a row with an error" "$out" '.named_prs.row out="$(GH_STUB_UNAUTH=1 GQL_STUB_JSON="$gql_doc" gather --json --prs acme/ops#7 "$clone" 2>/dev/null)"; rc=$? chk "an unauthenticated gh still exits 0" "$rc" jqok "unauthenticated gh is a field on every named row" "$out" '.named_prs.gh_state == "unauthenticated" and .named_prs.rows[0].error == "gh unauthenticated"' -chk "an unauthenticated gh makes no GraphQL call" "$([ ! -s "$GQL_STUB_CALLS" ]; echo $?)" +chk "an unauthenticated gh makes no GraphQL call" "$([ ! -s "$GQL_STUB_CALLS" ] && echo 0 || echo 1)" for bad in 'acme/ops' 'acme/ops#x' 'ac"me/ops#1' 'acme/ops#1) { x }' '../x#1'; do out="$(gather --json --prs "$bad" "$clone" 2>&1)"; rc=$? - chk "a malformed ref '$bad' is refused with exit 64" "$([ "$rc" -eq 64 ]; echo $?)" + chk "a malformed ref '$bad' is refused with exit 64" "$([ "$rc" -eq 64 ] && echo 0 || echo 1)" done chk_has "the refusal names the expected shape" "$out" "is not owner/name#n" @@ -347,7 +347,7 @@ chk_no "keep sweep rows are only counted" "$sum" "fresh branch, no own commits" txt="$(GH_STUB_PR_7="$open7" gather --text "$clone" 2>/dev/null)" chk_has "--text on the gather is the summary view" "$txt" "wrap-session/1 generated_at=" out="$(gather --json --summary "$clone" 2>&1)"; rc=$? -chk "--json with --summary is refused" "$([ "$rc" -eq 64 ]; echo $?)" +chk "--json with --summary is refused" "$([ "$rc" -eq 64 ] && echo 0 || echo 1)" # =========================================================================== echo "=== --mark-dir: step 0's writer check rides the gather ===" @@ -358,7 +358,7 @@ out="$(gather --json --mark-dir "$marks" --since "$since" --self "$TMPD/wt-prs-c chk "a gather with --mark-dir exits 0" "$rc" key="$(cd "$clone" && pwd -P | sed 's#^/##; s#/#-#g')" marks="$(cd "$marks" && pwd -P)" -chk "the mark file is written under a slash-free repo key" "$([ -f "$marks/writers-$key.json" ]; echo $?)" +chk "the mark file is written under a slash-free repo key" "$([ -f "$marks/writers-$key.json" ] && echo 0 || echo 1)" jqok "the repo row carries the writer facts and the mark path" "$out" ".repos[0].writers.schema == \"wrap-writers/1\" and .repos[0].writers.writer_mark.write == \"$marks/writers-$key.json\" and .repos[0].writers.since == $since" chk "the written mark passes the later --check-mark" "$("$WRAP" session --writers --check-mark "$marks/writers-$key.json" --self "$TMPD/wt-prs-clean" "$clone" 2>/dev/null | jq -e '.writer_mark.valid == true' >/dev/null; echo $?)" gda="$(git -C "$clone" rev-parse --path-format=absolute --git-dir)" @@ -369,9 +369,9 @@ chk_has "foreign activity shows in the summary" "$sum" "writers foreign_activity chk_has "the foreign worktree is named" "$sum" "foreign $TMPD_P/clone-prs branch=main index_lock=true" chk_has "the header counts repos with foreign activity" "$sum" "foreign_activity_repos=1" out="$(gather --json --mark "$TMPD/x.json" "$clone" 2>&1)"; rc=$? -chk "--mark on the gather is refused (it belongs to --writers)" "$([ "$rc" -eq 64 ]; echo $?)" +chk "--mark on the gather is refused (it belongs to --writers)" "$([ "$rc" -eq 64 ] && echo 0 || echo 1)" out="$("$WRAP" session --writers --prs acme/ops#1 "$clone" 2>&1)"; rc=$? -chk "--prs on --writers is refused" "$([ "$rc" -eq 64 ]; echo $?)" +chk "--prs on --writers is refused" "$([ "$rc" -eq 64 ] && echo 0 || echo 1)" # =========================================================================== echo "=== --transcript: the script reads repos, PR URLs and the opening epoch ===" @@ -395,7 +395,7 @@ jqok "a cwd, an Edit path and a removed worktree all resolve to one main checkou jqok "PR URLs come from the lead and subagent transcripts" "$out" '.transcript.prs == ["acme/ops#6190","acme/ops#7","acme/dots#1051"] and .transcript.subagent_transcripts == 1' jqok "a PR a create or merge command names is acted, a quoted URL only mentioned" "$out" '.transcript.acted_prs == ["acme/ops#6190","acme/ops#7"] and ([.named_prs.rows[] | {(.ref): .session}] | add) == {"acme/ops#6190":"acted","acme/ops#7":"acted","acme/dots#1051":"mentioned"}' jqok "the transcript PRs are read live with the named ones" "$out" '[.named_prs.rows[].ref] == ["acme/ops#6190","acme/ops#7","acme/dots#1051"] and .named_prs.rows[2].state == "MERGED"' -chk "transcript PRs and --prs still cost one GraphQL call" "$([ "$(wc -l < "$GQL_STUB_CALLS" | tr -d ' ')" = 1 ]; echo $?)" +chk "transcript PRs and --prs still cost one GraphQL call" "$([ "$(wc -l < "$GQL_STUB_CALLS" | tr -d ' ')" = 1 ] && echo 0 || echo 1)" out="$(GQL_STUB_JSON="$gql_doc" gather --json --transcript "$tfile" --prs acme/ops#7 --since 1700000000 "$clone" 2>/dev/null)" jqok "an explicit --since wins and a named repo is not gathered twice" "$out" '.since == 1700000000 and (.repos | length) == 1 and ([.named_prs.rows[].ref] | index("acme/ops#7")) != null' sum="$(GQL_STUB_JSON="$gql_doc" gather --summary --transcript "$tfile" 2>/dev/null)" @@ -405,13 +405,13 @@ chk_has "the summary names the transcript facts" "$sum" "transcript started_at_e printf '#!/bin/sh\ntouch "%s/fsmonitor-ran"\nexit 1\n' "$TMPD" > "$TMPD/fsmon.sh"; chmod +x "$TMPD/fsmon.sh" git -C "$clone" config core.fsmonitor "$TMPD/fsmon.sh" gather --json "$clone" >/dev/null 2>&1 -chk "control: a planted core.fsmonitor fires on a plain gather" "$([ -e "$TMPD/fsmonitor-ran" ]; echo $?)" +chk "control: a planted core.fsmonitor fires on a plain gather" "$([ -e "$TMPD/fsmonitor-ran" ] && echo 0 || echo 1)" rm -f "$TMPD/fsmonitor-ran" GQL_STUB_JSON="$gql_doc" gather --json --transcript "$tfile" >/dev/null 2>&1 -chk "a planted core.fsmonitor never fires for a transcript-named repo" "$([ ! -e "$TMPD/fsmonitor-ran" ]; echo $?)" +chk "a planted core.fsmonitor never fires for a transcript-named repo" "$([ ! -e "$TMPD/fsmonitor-ran" ] && echo 0 || echo 1)" git -C "$clone" config --unset core.fsmonitor out="$(gather --json --transcript "$TMPD/no-such.jsonl" "$clone" 2>&1)"; rc=$? -chk "a missing transcript file is refused" "$([ "$rc" -eq 64 ]; echo $?)" +chk "a missing transcript file is refused" "$([ "$rc" -eq 64 ] && echo 0 || echo 1)" echo if [ "$FAIL" -gt 0 ]; then echo "test-wrap-session: $PASS passed, $FAIL FAILED of $TOTAL" >&2; exit 1; fi From 43a3cecbeb790b94ce3f4a922edb6b24a01a8f44 Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 11:38:27 +0700 Subject: [PATCH 07/19] docs(wrap): run the miner in the foreground and tighten needs-you Replay round 3 found the lead polling a background miner (sleep loops, output-file globs, agent listings), one run ending on a note after the report, a handed-off PR shown MERGED in prose and OPEN in the table, an invented owner decision for a choice a worker made, and leads reading the lint's source. The miner now runs with run_in_background false; a handed-off PR keeps the one state its live search printed; a choice the session made is not an owner action; the lint's source is never read. --- commands/wrap.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/commands/wrap.md b/commands/wrap.md index afd0ddf4..f26e36d7 100644 --- a/commands/wrap.md +++ b/commands/wrap.md @@ -12,7 +12,7 @@ Run after `/kit:ship`, at session end, or when the operator asks to land work. N The distill half is the candidate scan, both seams, steps 7a-7c, and the drain. It is on unless the operator root config sets `wrap.distill = false`; `harvest` hands it to the harvest sweep only when `/sweep/installed` exists and `harvest.enable` is true. With distill off, skip those distill steps by name and report `SKIPPED: distill off`. The retro is landing, not distill, and still runs when its ledger condition is met. Harvest mode reports `SKIPPED: distill runs in the harvest sweep`; in phase 1 the sweep reports candidates and builds none. Read `harvest_sweep.py --status` for the newest report. When the knob resolves as true but the marker is absent, the FYI row says `not installed on this host`. An explicit one-shot distill means the sweep will also see this session. -**Wrapping another session.** Never scan the wrapper's empty context. Use the transcript path the operator or the dispatch gives; when you have only a name, resolve it with `bin/session recall --name`; when you have only an id prefix, confirm it with `bin/session recall --tail `. Then make ONE digest call: `bin/session recall --replies `, every turn's prompt and final reply. In the SAME turn as the start gather, dispatch one read-only Sonnet miner over the transcript and its worker transcripts (list them with `bin/session recall --subagents` inside the miner's brief, not as a lead call). The miner returns only: the distill candidates (the candidate scan below, each with its evidence), the landing facts (PRs this session opened or merged, board rows and items it changed, work it handed to another agent), and the owner actions still open at the end. Use only its lists and the digest. The lead never reads a transcript into its own context. +**Wrapping another session.** Never scan the wrapper's empty context. Use the transcript path the operator or the dispatch gives; when you have only a name, resolve it with `bin/session recall --name`; when you have only an id prefix, confirm it with `bin/session recall --tail `. Then make ONE digest call: `bin/session recall --replies `, every turn's prompt and final reply. In the SAME turn as the start gather, dispatch one read-only Sonnet miner in the foreground (`run_in_background: false`, so its answer is the tool result; never poll, sleep, or list agents for it) over the transcript and its worker transcripts (list them with `bin/session recall --subagents` inside the miner's brief, not as a lead call). The miner returns only: the distill candidates (the candidate scan below, each with its evidence), the landing facts (PRs this session opened or merged, board rows and items it changed, work it handed to another agent), and the owner actions still open at the end. Use only its lists and the digest. The lead never reads a transcript into its own context. ## Start gather @@ -31,7 +31,7 @@ The gather holds config knobs, activity-log state, the named PRs, and per repo t **What the gather replaces.** Run none of these when the gather covers the fact: `git status`, `git log`, `git for-each-ref` or any other git read; `wrap scan` or a `wrap apply` dry run (the summary's `sweep` lines carry its verdicts); a grep, `rg`, `jq`, Glob or Read over the transcript or to find a repo; a re-read of the gather; `gh pr view` or `gh run list` one PR at a time (put the PR in `--prs`); a `--help` call. The target is 10 lead calls per wrap: this file, the digest, the gather with the miner beside it, the step 7b lookups, one `flick-7b`, and only the writes a decision needs. -**Handed-off work.** A change the session handed to another agent or bot ("X will open the PR") has no ref in the digest. Find it with one `gh pr list --repo --state all --search ""` and state only what that live read shows. Never call a PR or a handed-off change pending, open, or merged from the transcript alone. +**Handed-off work.** A change the session handed to another agent or bot ("X will open the PR") has no ref in the digest. Find it with one `gh pr list --repo --state all --search ""` and state only what that live read shows, with the same state in every place the PR appears. Never call a PR or a handed-off change pending, open, or merged from the transcript alone. `config` carries the root-only values of `wrap.distill`, `wrap.before`, `wrap.after`, `wrap.merge_own_prs`, `wrap.tidy_worktrees`, `wrap.delete_merged_remote_branches`, `wrap.carry_stray_lines`, `wrap.autoland_carry`, `wrap.build_candidates`, `kit_config_get_root wrap.build_lanes`, `wrap.drain_staged`, and the mode that `bin/wrap follow-mode [lanes|all]` resolves. Every false knob turns its write into a report line and earns a `STATE` row. @@ -80,9 +80,9 @@ The after seam invokes the configured `wrap.after` skill after landing. Empty is When any write step ran, run one final read-only gather over the same repos before drafting: `bin/wrap session --summary ...`. `Left alone` uses that final gather, never memory or the start snapshot. When no write ran (a dry run, or nothing to land), the start gather is the final state; do not gather again. -**Needs-you check, before writing `NOTHING`.** Walk the digest's replies and the miner's open owner actions, newest first. List every owner action they name: an ask to the operator, a blocker, a lettered `a.` `b.` item, "needs Han" or "needs you", an approval, and a merge, close, or click left to the owner. An action a later reply, the miner, or a gather row shows done is closed; leave it out. Every other one goes under `Needs you`. When the newest mention leaves it open but you cannot prove it still is, list it with `check`: `a. RUN check . .` Write `NOTHING` only when this walk found no open item, never because the gather shows nothing. +**Needs-you check, before writing `NOTHING`.** Walk the digest's replies and the miner's open owner actions, newest first. List every owner action they name: an ask to the operator, a blocker, a lettered `a.` `b.` item, "needs Han" or "needs you", an approval, and a merge, close, or click left to the owner. An action a later reply, the miner, or a gather row shows done is closed; leave it out. A choice the session or a worker made itself is not an owner action. Every other one goes under `Needs you`. When the newest mention leaves it open but you cannot prove it still is, list it with `check`: `a. RUN check . .` Write `NOTHING` only when this walk found no open item, never because the gather shows nothing. -Draft the skim-first report, write it to scratch. Run the lint before printing: `bash lib/wrap/report-lint.sh `. Fix or do what the lint names, then re-run. The shape is: +Draft the skim-first report, write it to scratch. Run the lint before printing: `bash lib/wrap/report-lint.sh `. Fix or do what the lint names, then re-run. Never read the lint's source; when it cannot run, say so in one `SKIPPED` FYI row. The shape is: ```markdown ## Wrap: From 0ff2815762957496a9a7b59d65bc0ac440d38f5f Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 11:39:25 +0700 Subject: [PATCH 08/19] test(shared-lookups): mark the intended word split for shellcheck --- tests/test-shared-lookups.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test-shared-lookups.sh b/tests/test-shared-lookups.sh index 3055d5e5..84460629 100644 --- a/tests/test-shared-lookups.sh +++ b/tests/test-shared-lookups.sh @@ -12,6 +12,7 @@ # Run: bash tests/test-shared-lookups.sh Exit 0 = all pass. # operator-layer: unpinned-ok names lib/wrap paths as data in the pinned list; reads files as text, runs no resolver set -uo pipefail +# shellcheck disable=SC2046 # splitting is the point: one env var name per word unset $(git rev-parse --local-env-vars) 2>/dev/null KIT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" TMPD="$(mktemp -d "${TMPDIR:-/tmp}/dk-shared-lookups.XXXXXX")" || exit 1 From 6809df3df8ffccaa064534098eb8adae468d28ab Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 12:00:40 +0700 Subject: [PATCH 09/19] docs(verification): record the wrap-cut-call replay and final proof --- docs/verification/wrap-cut-call.md | 96 ++++++++++++++++++++---------- 1 file changed, 64 insertions(+), 32 deletions(-) diff --git a/docs/verification/wrap-cut-call.md b/docs/verification/wrap-cut-call.md index df46515e..5d7cc9ce 100644 --- a/docs/verification/wrap-cut-call.md +++ b/docs/verification/wrap-cut-call.md @@ -2,15 +2,16 @@ Headless shell library and command-file change (`feat-wrap-cut-call`, off `origin/master` at `e75b5b2d`): no visible surface. -An A/B replay of `/kit:wrap` (ops-toolkit `experiments/wrap-ab-replay/`) found the new command worse than the old one on 2 of 6 sessions: B4 stated a stale PR state, and P3 printed `Needs you: NOTHING` while the owner still had an action. It also counted 127 lead calls over 6 wraps, against a target of 10 per wrap. This change gives `wrap session` the flags that let `commands/wrap.md` run one gather call, and adds a needs-you check. +An A/B replay of `/kit:wrap` (ops-toolkit `experiments/wrap-ab-replay/`) found the new command worse than the old one on 2 of 6 sessions: B4 stated a stale PR state, and P3 printed `Needs you: NOTHING` while the owner still had an action. It also counted 127 lead calls over 6 wraps, against a target of 10 per wrap. This change lets `commands/wrap.md` run one gather call and adds a needs-you check. ## What changed 1. `lib/wrap/wrap-session.sh`, on the gather (not `--writers`): - - `--prs owner/name#n,...` (also `https://github.com/owner/name/pull/n`, repeatable) resolves every ref in ONE `gh api graphql` call: state, merged, mergedAt, merge commit, head branch, base, draft, author. Refs are validated before they enter the query text. A ref GitHub cannot resolve stays a row with GitHub's error; no ref is dropped. A non-ok `gh` makes no call and marks each row. + - `--prs owner/name#n,...` (also `https://github.com/owner/name/pull/n`, repeatable) resolves every ref in ONE `gh api graphql` call: state, merged, mergedAt, merge commit and its check state, head branch, base, draft, author. Refs are validated before they enter the query text. A ref GitHub cannot resolve stays a row with GitHub's error. A non-ok `gh` makes no call and marks each row. + - `--transcript ` reads the lead and subagent transcripts in the script: the start epoch (first timestamp), every GitHub PR URL tagged `acted` (a PR-writing command named it) or `mentioned`, and the main checkout of every repo the session worked in. Those repos run with `core.fsmonitor` and `core.hooksPath` neutralized through git's env config, and only when the current user owns them. - `--summary` prints the gather as one fact per line (`--text` means the same on the gather). Sweep keep rows collapse to a count. - - `--mark-dir ` (with `--since`, `--self`) runs step 0's writer check and mark per repo inside the gather, writing `/writers-.json`. -2. `commands/wrap.md`: one `session recall --replies` digest, one gather, then the report. It names the calls the gather replaces, finds handed-off PRs with one live `gh pr list --search`, re-gathers only after a write, and walks the digest for owner actions before `Needs you` may say `NOTHING`. + - `--mark-dir ` (with `--since`, `--self`) runs step 0's writer check and mark per repo inside the gather. +2. `commands/wrap.md`: one `session recall --replies` digest, one gather with a foreground read-only miner beside it, then the report. It names the calls the gather replaces, finds handed-off PRs with one live `gh pr list --search`, credits only `acted` or miner-confirmed PRs in `Shipped`, re-gathers only after a write, and walks the digest and the miner's list for owner actions before `Needs you` may say `NOTHING`. ## Green runs @@ -19,77 +20,108 @@ Command: bash tests/test-wrap-session.sh Exit: 0 Output: === --prs: every named PR, one batched GraphQL call, live state === - PASS a gather with --prs exits 0 even when gh exits 1 on a partial error PASS four distinct refs across two repos cost exactly one GraphQL call PASS an open PR reads OPEN, never a cached merged state PASS an unresolvable PR stays a row with GitHub's error === --summary: one compact view of the same gather === PASS a named merged PR prints its live state and merge commit - PASS an own open PR prints pending and failed counts === --mark-dir: step 0's writer check rides the gather === PASS the written mark passes the later --check-mark - PASS foreign activity shows in the summary -test-wrap-session: all 122 passed +=== --transcript: the script reads repos, PR URLs and the opening epoch === + PASS a cwd, an Edit path and a removed worktree all resolve to one main checkout + PASS a PR a create or merge command names is acted, a quoted URL only mentioned + PASS control: a planted core.fsmonitor fires on a plain gather + PASS a planted core.fsmonitor never fires for a transcript-named repo +test-wrap-session: all 134 passed Verdict: PASS ``` ```text -Command: for t in test-meta-spec-depth test-wrap-report-lint test-wrap-cli test-wrap-start test-wrap-land test-wrap-ship test-wrap-rebase test-wrap-deploy test-meta-docs-registry test-ship-gate-impl-notes test-ship-pr-body-verified test-gate-validate-round; do bash tests/$t.sh; done +Command: for t in test-meta-spec-depth test-wrap-report-lint test-wrap-cli test-wrap-start test-wrap-ship test-wrap-deploy test-meta-docs-registry test-gate-validate-round test-ship-pr-body-verified test-wrap-rebase test-session-recall test-shared-lookups; do bash tests/$t.sh; done Exit: 0 Output: test-meta-spec-depth: All meta tests passed. test-wrap-report-lint: all 159 passed test-wrap-cli: all 106 passed test-wrap-start: all 143 passed -test-wrap-land: all 889 passed test-wrap-ship: all 120 passed -test-wrap-rebase: all 104 passed test-wrap-deploy: all 176 passed test-meta-docs-registry: Passed 123 / 123 -test-ship-gate-impl-notes: PASS=19 FAIL=0 -test-ship-pr-body-verified: 7/7 passed test-gate-validate-round: 202/202 pass, 0 fail -Verdict: PASS (every suite that reads commands/wrap.md) +test-ship-pr-body-verified: 7/7 passed +test-wrap-rebase: all 104 passed +PASS: session-recall +test-shared-lookups: all 15 passed +Verdict: PASS (every suite that reads commands/wrap.md, plus the two CI named) ``` ```text -Command: shellcheck -s bash -x lib/wrap/wrap-session.sh +Command: shellcheck -S warning lib/wrap/wrap-session.sh tests/test-wrap-session.sh tests/test-shared-lookups.sh Exit: 0 Output: (no findings) Verdict: PASS ``` +CI on PR #1257 at `0ff28157`: test (ubuntu-latest, fast), test (macos-latest, fast), test (summary), pr-shape, owners, plan, secret-scan all pass. + ## Negative control ```text Command: bash scripts/negctl.sh "bash tests/test-wrap-session.sh" "git show origin/master:lib/wrap/wrap-session.sh >| lib/wrap/wrap-session.sh" Exit: 1 Output: - FAIL --text on the gather is the summary view - PASS --json with --summary is refused -=== --mark-dir: step 0's writer check rides the gather === - FAIL a gather with --mark-dir exits 0 - FAIL the mark file is written under a slash-free repo key - FAIL the repo row carries the writer facts and the mark path - FAIL the written mark passes the later --check-mark - FAIL foreign activity shows in the summary - FAIL the foreign worktree is named - FAIL the header counts repos with foreign activity - FAIL --mark on the gather is refused (it belongs to --writers) - PASS --prs on --writers is refused - -test-wrap-session: 78 passed, 44 FAILED of 122 + FAIL an explicit --since wins and a named repo is not gathered twice + FAIL the summary names the transcript facts + PASS a missing transcript file is refused + +test-wrap-session: 81 passed, 53 FAILED of 134 Verdict: RED, as expected ``` -The 11 new cases that pass on master are refusals (master refuses the unknown flags with exit 64 too) and two `chk_no` lines. +The new cases that pass on master are refusals (master refuses the unknown flags with exit 64 too), `chk_no` lines, and the fsmonitor control. + +## Replay (ops-toolkit harness, NEW arm only) + +Harness: ops-toolkit `experiments/wrap-ab-replay/` at `origin/main` `1e72f1ea`, copied to a scratch dir with the OLD streams, reports and A/B key. Deltas, NEW arm only: the kit root points at a `git archive` snapshot of the tested commit (`WRAP_AB_KIT`), the command file is that commit's `commands/wrap.md`, and a NEW-only driver keeps the same stops (rate-limit event not `allowed`, seven-day at or above 0.70, cap 700k output tokens, 2 runs at a time under `nice -n 10`). Facts sheets were rebuilt and all six pairs re-judged with the same judge prompt, model and key. + +Four rounds ran; each fixed what the last one showed. Scored round: `43a3cecb`; the one later commit only adds a shellcheck directive to a test. + +| Round | Commit | What it changed | Rule 1 (NEW at least OLD) | Lead calls median | Wall s median | +|---|---|---|---|---|---| +| 1 | `323baebb` | `--prs`, `--summary`, `--mark-dir` | not judged | 15.5 | 105 | +| 2 | `2d845291` | `--transcript` (repos, PRs, start epoch); miner made optional | 1 of 6 | 6.5 | 109.5 | +| 3 | `11d87a91` | acted/mentioned PR tags; miner back beside the gather | 3 of 6 | 14.5 | 232 | +| 4 | `43a3cecb` | foreground miner, tighter needs-you, no lint-source reads | 5 of 6 | 10.5 | 237.5 | + +| Session | OLD rows | OLD | NEW rows | NEW | Lead calls OLD / prior NEW / now | Wall s OLD / now | +|---|---|---|---|---|---|---| +| W2 | 2 1 2 2 1 1 | 9 | 2 1 2 2 1 2 | 10 | 29 / 22 / 7 | 309 / 224 | +| W3 | 2 2 2 1 1 1 | 9 | 2 2 1 2 1 2 | 10 | 40 / 28 / 16 | 366 / 226 | +| B1 | 1 1 1 2 0 2 | 7 | 2 2 2 2 1 1 | 10 | 36 / 28 / 11 | 385 / 249 | +| B4 | 2 2 2 1 1 2 | 10 | 1 2 2 2 1 2 | 10 | 20 / 14 / 10 | 269 / 254 | +| P2 | 2 1 1 1 1 1 | 7 | 2 2 2 2 2 2 | 12 | 32 / 11 / 11 | 308 / 185 | +| P3 | 2 2 1 2 2 2 | 11 | 2 2 2 2 1 1 | 10 | 21 / 24 / 9 | 482 / 389 | + +```text +Command: python3 -I harness/score.py . +Exit: 0 +Output: +new_at_least_old 5, row_drops [], rule1 true, rule2 true, rule3 true, pass true +medians old: tool_calls_total 84, tool_calls_lead 30.5, wall_s 337.5, output_tokens 33310 +medians new: tool_calls_total 37, tool_calls_lead 10.5, wall_s 237.5, output_tokens 21461 +Verdict: PASS on the pre-registered rule; lead calls median 10.5 misses the 10 target by 0.5 +``` + +Lead calls by kind, scored round: `precedent find` (step 7b, frozen) is 3 to 7 per session; every other lead call has a median of 6.5. + +Stops and writes: every `rate_limit_event` `allowed`, seven-day 0.46 to 0.48. A stream audit found no write-shaped command; the hits were text inside `jq` filters and `precedent find` queries. Repo digests before and after each round moved only from concurrent sessions on the host (an ops-toolkit `pull --rebase`, board-mirror scratch files, a dfoundation `main` advance) and this branch's own commits. ## Not proven locally -- The full suite (`bash tests/run-all.sh`) did not run: the host was loaded, so only the suites that read the touched files ran. CI is the second opinion. +- The full suite (`bash tests/run-all.sh`) did not run locally: the host was loaded. CI's `--changed` run passed. - `wrap.sh` usage and `docs/reference/wrap.md` do not yet name the new flags: another session holds those files. ## Rollback -Revert the commit. The new flags are additive; `--json` output only gains `named_prs` and two summary counts. +Revert the commits. The new flags are additive; `--json` output only gains `named_prs`, `transcript`, `since`, per-repo `writers` when asked, and two summary counts. From 6c9a0cfc67f05d6bb08738489937b7604cf0c817 Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 12:13:39 +0700 Subject: [PATCH 10/19] docs(wrap): scope transcript-only repos and the self-wrap needs-you walk A repo that --transcript adds because the session only read it gets no pull, tidy, board flip or activity line. A self-wrap has no digest or miner, so its needs-you walk reads its own replies. Wording only, after the scored replay round; not re-scored. --- commands/wrap.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/wrap.md b/commands/wrap.md index f26e36d7..39027341 100644 --- a/commands/wrap.md +++ b/commands/wrap.md @@ -43,7 +43,7 @@ Then, when `config.before` names a skill, invoke it ahead of step 0 while the un ## Landing pass -Run these steps once per repo, in order. Before every write step (steps 1, 2, 3, 4, 6, 7, and 8, plus any seam or distill write into the repo), re-check live against that mark: +Run these steps once per repo, in order. A repo `--transcript` added that the session only read (no `acted` PR, commit, or edit there by the digest or the miner) is facts only: no pull, tidy, board flip, or activity line there. Before every write step (steps 1, 2, 3, 4, 6, 7, and 8, plus any seam or distill write into the repo), re-check live against that mark: ```bash bin/wrap session --writers --check-mark "$writers_mark" [--self ]... @@ -80,7 +80,7 @@ The after seam invokes the configured `wrap.after` skill after landing. Empty is When any write step ran, run one final read-only gather over the same repos before drafting: `bin/wrap session --summary ...`. `Left alone` uses that final gather, never memory or the start snapshot. When no write ran (a dry run, or nothing to land), the start gather is the final state; do not gather again. -**Needs-you check, before writing `NOTHING`.** Walk the digest's replies and the miner's open owner actions, newest first. List every owner action they name: an ask to the operator, a blocker, a lettered `a.` `b.` item, "needs Han" or "needs you", an approval, and a merge, close, or click left to the owner. An action a later reply, the miner, or a gather row shows done is closed; leave it out. A choice the session or a worker made itself is not an owner action. Every other one goes under `Needs you`. When the newest mention leaves it open but you cannot prove it still is, list it with `check`: `a. RUN check . .` Write `NOTHING` only when this walk found no open item, never because the gather shows nothing. +**Needs-you check, before writing `NOTHING`.** Walk the digest's replies and the miner's open owner actions, newest first; a self-wrap has neither, so it walks its own replies and asks this session. List every owner action they name: an ask to the operator, a blocker, a lettered `a.` `b.` item, "needs Han" or "needs you", an approval, and a merge, close, or click left to the owner. An action a later reply, the miner, or a gather row shows done is closed; leave it out. A choice the session or a worker made itself is not an owner action. Every other one goes under `Needs you`. When the newest mention leaves it open but you cannot prove it still is, list it with `check`: `a. RUN check . .` Write `NOTHING` only when this walk found no open item, never because the gather shows nothing. Draft the skim-first report, write it to scratch. Run the lint before printing: `bash lib/wrap/report-lint.sh `. Fix or do what the lint names, then re-run. Never read the lint's source; when it cannot run, say so in one `SKIPPED` FYI row. The shape is: From 2edc01f4a52f560975b9bebec12685345823b404 Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 12:15:49 +0700 Subject: [PATCH 11/19] docs(verification): link the replay results and note judge noise --- docs/verification/wrap-cut-call.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/verification/wrap-cut-call.md b/docs/verification/wrap-cut-call.md index 5d7cc9ce..dec2411d 100644 --- a/docs/verification/wrap-cut-call.md +++ b/docs/verification/wrap-cut-call.md @@ -115,7 +115,9 @@ Verdict: PASS on the pre-registered rule; lead calls median 10.5 misses the 10 t Lead calls by kind, scored round: `precedent find` (step 7b, frozen) is 3 to 7 per session; every other lead call has a median of 6.5. -Stops and writes: every `rate_limit_event` `allowed`, seven-day 0.46 to 0.48. A stream audit found no write-shaped command; the hits were text inside `jq` filters and `precedent find` queries. Repo digests before and after each round moved only from concurrent sessions on the host (an ops-toolkit `pull --rebase`, board-mirror scratch files, a dfoundation `main` advance) and this branch's own commits. +Stops and writes: every `rate_limit_event` `allowed`, seven-day 0.46 to 0.48. A stream audit found no write-shaped command; the hits were text inside `jq` filters and `precedent find` queries. Repo digests before and after each round moved only from concurrent sessions on the host (a `pull --rebase`, board-mirror scratch files, a `main` advance) and this branch's own commits. The raw scores, metrics, digests and harness deltas are in ops-toolkit PR #6521 (`experiments/wrap-ab-replay/results/rerun-new-43a3cecb/`). + +Against the merged OLD totals (judged before this work), round 4 NEW also holds 5 of 6 with no 2-point row drop. Judge noise is large: the same OLD report scored 11, 9 and 7 for P2 across rounds. The command was tuned over four rounds on these six sessions. Commit `6c9a0cfc` (self-wrap and read-only-repo wording) came after the scored round and is not re-scored. ## Not proven locally From 37b3ac23178fb059921aa5d5d79bac933283713d Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 12:31:42 +0700 Subject: [PATCH 12/19] docs(wrap): run step 7b's precedent find once per wrap Step 7b now makes one `precedent find --surface inventory --json` call with every candidate's key words in a single query (the CLI takes one description), then matches each candidate to its hits. This caps the lookups that made 3 to 7 lead calls per wrap in the replay. Not re-scored: the six replay sessions are spent as a test set. --- commands/wrap.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/wrap.md b/commands/wrap.md index 39027341..5bf66597 100644 --- a/commands/wrap.md +++ b/commands/wrap.md @@ -29,7 +29,7 @@ bin/wrap session --summary [--transcript ] --mark-dir "$scratch" [-- The gather holds config knobs, activity-log state, the named PRs, and per repo the checkout, dirty files, worktrees, writer facts, active board rows, handoffs, own open PRs with check totals and gates, recent merge deploy state, and the sweep report. Treat it as facts, not as proof of intent. Rows this session did not touch stay untouched. -**What the gather replaces.** Run none of these when the gather covers the fact: `git status`, `git log`, `git for-each-ref` or any other git read; `wrap scan` or a `wrap apply` dry run (the summary's `sweep` lines carry its verdicts); a grep, `rg`, `jq`, Glob or Read over the transcript or to find a repo; a re-read of the gather; `gh pr view` or `gh run list` one PR at a time (put the PR in `--prs`); a `--help` call. The target is 10 lead calls per wrap: this file, the digest, the gather with the miner beside it, the step 7b lookups, one `flick-7b`, and only the writes a decision needs. +**What the gather replaces.** Run none of these when the gather covers the fact: `git status`, `git log`, `git for-each-ref` or any other git read; `wrap scan` or a `wrap apply` dry run (the summary's `sweep` lines carry its verdicts); a grep, `rg`, `jq`, Glob or Read over the transcript or to find a repo; a re-read of the gather; `gh pr view` or `gh run list` one PR at a time (put the PR in `--prs`); a `--help` call. The target is 10 lead calls per wrap: this file, the digest, the gather with the miner beside it, the one step 7b lookup, one `flick-7b`, and only the writes a decision needs. **Handed-off work.** A change the session handed to another agent or bot ("X will open the PR") has no ref in the digest. Find it with one `gh pr list --repo --state all --search ""` and state only what that live read shows, with the same state in every place the PR appears. Never call a PR or a handed-off change pending, open, or merged from the transcript alone. @@ -70,7 +70,7 @@ Landing retro: after the per-repo pass, run `/kit:retro` only when a run ledger Step 7a writes the DEBT marker. Every skip in 7a skips only 7a; 7b and 7c still run. Capture `rid_out` and `rid_rc` exactly. A non-zero `rid_rc` prints `skipped (structural): DEBT marker impossible this run ()`; Do not synthesize a rid. Then use the run log and `bash lib/classify/significance-classify.sh record ""`. A configured teacher from `bash lib/gate/quiz-gate.sh teacher` receives the record; empty prints `skipped: no teacher`. -Step 7b acts on the scan list written before landing, never on a fresh recollection. For each candidate run `bin/precedent find --surface inventory --json`, open the top hit before deciding, and prefer a code home over prose. Then classify with `bash lib/classify/lane-classify.sh risk`. `wrap.build_candidates` false still classifies and reports. `wrap.build_lanes` decides which lanes build inline; `full` never builds inline. Build in the home repo through `bin/wrap start /`, dispatch a worker, verify once, and report the quoted check. Sonnet is the default worker; Opus takes security, money, data models, and verification; Haiku takes mechanical fan-out. Everything else is REPORTED in the report only: it never mints a board row or a staging block. A whole-cover hit is a NOTE with a pointer written in-session. Run `bin/wrap flick-7b` once, piping one ` ` pair per line (with no pair, run it once with empty stdin), and carry its `STATE` row verbatim. +Step 7b acts on the scan list written before landing, never on a fresh recollection. Run `bin/precedent find --surface inventory --json --limit <3 per candidate>` ONCE per wrap, with every candidate's key words in that one query (the CLI takes one description, not several queries). Match each candidate to its hits, open its top hit before deciding, and prefer a code home over prose. Then classify with `bash lib/classify/lane-classify.sh risk`. `wrap.build_candidates` false still classifies and reports. `wrap.build_lanes` decides which lanes build inline; `full` never builds inline. Build in the home repo through `bin/wrap start /`, dispatch a worker, verify once, and report the quoted check. Sonnet is the default worker; Opus takes security, money, data models, and verification; Haiku takes mechanical fan-out. Everything else is REPORTED in the report only: it never mints a board row or a staging block. A whole-cover hit is a NOTE with a pointer written in-session. Run `bin/wrap flick-7b` once, piping one ` ` pair per line (with no pair, run it once with empty stdin), and carry its `STATE` row verbatim. Step 7c writes one memory note per incident whose root cause was our mistake, plus its index line. No incidents prints `skipped: no incidents`. For each note written, resolve `bash lib/gate/quiz-gate.sh teacher`; empty prints `skipped: no teacher` with the note path, and a named teacher receives the note path and incident file. The drain of hand-staged rows runs only when `wrap.drain_staged` is true. From ccdad400608d7b8483b9c2af0b6369df0ac27712 Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 13:07:12 +0700 Subject: [PATCH 13/19] fix(wrap): transcript repo discovery, truncated lines, URL-less merges, mark-dir guard Review fixes on the one-call gather: - The cd / git -C scan indexed a string, so jq errored and no such target was ever gathered (and the rest of that line's paths were lost). It now takes each capture's first group. - Transcripts are parsed line by line; a line that is not a JSON object is counted in transcript.skipped_lines (and the summary) instead of stopping the read and dropping every later repo and acted PR. - gh pr merge|ready|close with no URL and no --repo resolves against the origin of the repo it ran in (its last cd, else the record's cwd); with no number, against the record's git branch. Both go to the live --prs read. - --mark-dir refuses an empty path (step 0 would skip silently), $HOME, and any path inside a git work tree (marks would show as dirty files there). ## How I verified it bash tests/test-wrap-session.sh -> test-wrap-session: all 149 passed bash tests/test-shared-lookups.sh -> test-shared-lookups: all 15 passed --- lib/wrap/wrap-session.sh | 83 +++++++++++++++++++++++++++++------- tests/test-shared-lookups.sh | 2 +- tests/test-wrap-session.sh | 59 ++++++++++++++++++++++++- 3 files changed, 126 insertions(+), 18 deletions(-) diff --git a/lib/wrap/wrap-session.sh b/lib/wrap/wrap-session.sh index 09250611..c0fc5d8e 100644 --- a/lib/wrap/wrap-session.sh +++ b/lib/wrap/wrap-session.sh @@ -563,38 +563,79 @@ _session_config_json() { # cwd, each Edit/Write path, each `git -C` or `cd` target). A path that no longer exists walks up to # its nearest existing parent, so a removed worktree still names its repo. _session_transcript_json() { - local t="$1" start prs acted paths p d main repos_json + local t="$1" start prs acted paths p d main repos_json clean lead_clean skipped bare raw + local dir slug n branch ref url local -a tfiles=("$t") for p in "${t%.jsonl}"/subagents/*.jsonl; do [ -f "$p" ] && tfiles+=("$p"); done - start="$(jq -r 'select(.timestamp != null) | .timestamp' "$t" 2>/dev/null | head -n 1 \ + # Parse line by line, so one truncated line (a live self-wrap, a crashed worker) costs only that + # line; the count of lines that are not a JSON object is reported, never dropped in silence. + clean="$(mktemp "${TMPDIR:-/tmp}/kit.XXXXXX")"; lead_clean="$(mktemp "${TMPDIR:-/tmp}/kit.XXXXXX")" + jq -cR 'select(length > 0) | (fromjson? | select(type == "object")) // {"__bad":true}' "$t" > "$lead_clean" 2>/dev/null + for p in "${tfiles[@]:1}"; do + jq -cR 'select(length > 0) | (fromjson? | select(type == "object")) // {"__bad":true}' "$p" 2>/dev/null + done | cat "$lead_clean" - > "$clean" + skipped="$(jq -s '[.[] | select(.__bad == true)] | length' "$clean" 2>/dev/null)" + case "$skipped" in ''|*[!0-9]*) skipped=0 ;; esac + start="$(jq -r 'select(.timestamp != null) | .timestamp' "$lead_clean" 2>/dev/null | head -n 1 \ | jq -R 'sub("\\.[0-9]+Z$"; "Z") | try fromdateiso8601 catch empty' 2>/dev/null)" case "$start" in ''|*[!0-9]*) start=null ;; esac prs="$(cat "${tfiles[@]}" 2>/dev/null | grep -Eo 'https://github\.com/[A-Za-z0-9][A-Za-z0-9-]*/[A-Za-z0-9_.-]+/pull/[0-9]+' \ | sed -E 's#^https://github\.com/([^/]+)/([^/]+)/pull/([0-9]+)$#\1/\2\#\3#' | awk '!seen[$0]++' | head -n 50 | _session_lines_json)" [ -n "$prs" ] || prs='[]' # The PRs this session acted on: a URL in a PR-writing command or its output (gh pr create, merge, - # ready, close; wrap land, ship, merge), or `gh pr merge|ready|close --repo `. + # ready, close; wrap land, ship, merge), or `gh pr merge|ready|close [] [--repo ]`. + # A merge with no URL and no --repo resolves against the origin of the repo it ran in (its last + # `cd` target, else the record's cwd), and one with no number against that record's git branch. # Every other URL was only mentioned, and a report never credits the session with it. - acted="$(jq -rn ' - [inputs | .message.content[]? | select(type == "object")] as $b + raw="$(jq -rn ' + [inputs | select(.__bad != true) | . as $r | .message.content[]? | select(type == "object") + | . + {_cwd:($r.cwd // ""), _branch:($r.gitBranch // "")}] as $b | [$b[] | select(.type == "tool_use" and .name == "Bash") | select((.input.command // "") | test("gh +pr +(create|merge|ready|close)|wrap +(land|ship|merge)"))] as $acts | ($acts | map(.id)) as $ids | ($acts[] | .input.command), ($b[] | select(.type == "tool_result" and (.tool_use_id as $t | $ids | index($t))) | .content | tostring), - ($acts[] | .input.command - | ([scan("(?:--repo|-R)[ =]+([A-Za-z0-9][A-Za-z0-9-]*/[A-Za-z0-9_.-]+)")[0]] | first) as $r - | select($r != null) | scan("gh +pr +(?:merge|ready|close) +([0-9]+)")[0] | "https://github.com/\($r)/pull/\(.)") - ' "${tfiles[@]}" 2>/dev/null | grep -Eo 'https://github\.com/[A-Za-z0-9][A-Za-z0-9-]*/[A-Za-z0-9_.-]+/pull/[0-9]+' \ + ($acts[] | (.input.command // "") as $c | ._cwd as $cwd | ._branch as $br | select($c | test("gh +pr +(merge|ready|close)")) + | select($c | test("https://github\\.com/[^ ]+/pull/[0-9]+") | not) + | ([$c | scan("(?:--repo|-R)[ =]+([A-Za-z0-9][A-Za-z0-9-]*/[A-Za-z0-9_.-]+)") | .[0]] | first // "") as $repo + | ([$c | scan("gh +pr +(?:merge|ready|close) +([0-9]+)") | .[0]] | first // "") as $n + | ([$c | scan("\\bcd\\s+(\"[^\"]+\"|'"'"'[^'"'"']+'"'"'|[^\\s;&|)]+)") | .[0]] | last // $cwd) as $dir + | if $repo != "" and $n != "" then "https://github.com/\($repo)/pull/\($n)" + else "\u0001BARE\u001f\($dir)\u001f\($repo)\u001f\($n)\u001f\($br)" end) + ' "$clean" 2>/dev/null)" + bare="$(printf '%s\n' "$raw" | grep -a "$(printf '^\001BARE')" | cut -c2-)" + acted="$( { printf '%s\n' "$raw" | grep -av "$(printf '^\001BARE')" + # \037 (unit separator), not a tab: IFS would fold a run of tabs and shift empty fields. + while IFS="$(printf '\037')" read -r _ dir slug n branch; do + [ -n "$dir$slug" ] || continue + if [ -z "$slug" ]; then + d="$(printf '%s' "$dir" | tr -d "\"'" | sed "s#^~/#$HOME/#")" + while [ -n "$d" ] && [ "$d" != "/" ] && [ ! -d "$d" ]; do d="$(dirname "$d")"; done + [ -d "$d" ] && [ "$d" != "/" ] || continue + main="$(_session_main_checkout "$d" 2>/dev/null)" || continue + slug="$(_session_repo_slug "$(git -C "$main" remote get-url origin 2>/dev/null)" 2>/dev/null)" + fi + [ -n "$slug" ] || continue + if [ -z "$n" ] && [ -n "$branch" ] && [ "$(_gh_state)" = ok ]; then + n="$(gh pr list --repo "$slug" --head "$branch" --state all --limit 1 --json number --jq '.[0].number // empty' 2>/dev/null)" # merged-ok: names the PR a branch-only merge acted on, read live after; never a deletion proof + fi + case "$n" in ''|*[!0-9]*) continue ;; esac + printf 'https://github.com/%s/pull/%s\n' "$slug" "$n" + done </dev/null | tr -d "\"'" | sed "s#^~/#$HOME/#" | grep '^/' | awk '!seen[$0]++')" + ((.command // "") | [scan("(?:git\\s+-C|\\bcd)\\s+(\"[^\"]+\"|'"'"'[^'"'"']+'"'"'|[^\\s;&|)]+)") | .[0]] | .[]))) + ' "$clean" 2>/dev/null | tr -d "\"'" | sed "s#^~/#$HOME/#" | grep '^/' | awk '!seen[$0]++')" + rm -f "$clean" "$lead_clean" repos_json="$(while IFS= read -r p; do [ -n "$p" ] || continue d="$p" @@ -609,9 +650,8 @@ EOF_SESSION_TPATHS )" [ -n "$repos_json" ] || repos_json='[]' jq -cn --arg path "$t" --argjson start "$start" --argjson prs "$prs" --argjson repos "$repos_json" \ - --argjson subagents "$(( ${#tfiles[@]} - 1 ))" \ - --argjson acted "$acted" \ - '{path:$path,started_at_epoch:$start,subagent_transcripts:$subagents,prs:$prs,acted_prs:$acted,repos:$repos}' + --argjson subagents "$(( ${#tfiles[@]} - 1 ))" --argjson acted "$acted" --argjson skipped "$skipped" \ + '{path:$path,started_at_epoch:$start,subagent_transcripts:$subagents,skipped_lines:$skipped,prs:$prs,acted_prs:$acted,repos:$repos}' } # _session_pr_refs ... -- every PR ref as `owner/name#n`, one per line, deduplicated. @@ -688,7 +728,7 @@ _session_summary_text() { "wrap-session/1 generated_at=\(.generated_at) epoch=\(.generated_at_epoch) repos=\(.summary.repos) open_own_prs=\(.summary.open_own_prs) pending_prs=\(.summary.pending_prs) named_prs=\(.summary.named_prs) foreign_activity_repos=\(.summary.foreign_activity_repos)", "config " + (.config | to_entries | map("\(.key)=\(.value | v)") | join(" ")), (.transcript // null | select(. != null) | - "transcript started_at_epoch=\(.started_at_epoch | v) subagent_transcripts=\(.subagent_transcripts) repos=\(.repos | join(",") | if . == "" then "-" else . end) prs=\(.prs | length) acted_prs=\(.acted_prs | join(",") | if . == "" then "-" else . end)"), + "transcript started_at_epoch=\(.started_at_epoch | v) subagent_transcripts=\(.subagent_transcripts) skipped_lines=\(.skipped_lines) repos=\(.repos | join(",") | if . == "" then "-" else . end) prs=\(.prs | length) acted_prs=\(.acted_prs | join(",") | if . == "" then "-" else . end)"), "writer_since=\(.since | v)", "activity_log configured=\(.activity_log.configured) target=\(.activity_log.resolved | v) writable=\(.activity_log.writable) error=\(.activity_log.error | v)", (.named_prs // null | select(. != null) | @@ -785,6 +825,8 @@ cmd_session() { --prs) [ $# -ge 2 ] || { echo "$gusage" >&2; return 64; } pr_words+=("$2"); shift 2; continue ;; --mark-dir) [ $# -ge 2 ] || { echo "$gusage" >&2; return 64; } + # An empty value (an unset $scratch) would skip step 0's check without a word. + [ -n "$2" ] || { echo "wrap.sh session --mark-dir: empty path; step 0's writer check needs a scratch directory" >&2; return 64; } mark_dir="$2"; shift 2; continue ;; --transcript) [ $# -ge 2 ] || { echo "$gusage" >&2; return 64; } transcript="$2"; shift 2; continue ;; @@ -870,6 +912,15 @@ EOF_SESSION_TREPOS refs="$(_session_pr_refs "${pr_words[@]}")" || return 64 fi if [ -n "$mark_dir" ]; then + # Mark files are scratch state: never $HOME itself and never inside a git work tree, where + # they would show as dirty files and step 3 could commit them. Judge the nearest existing + # ancestor, before anything is created. + key="$mark_dir" + while [ -n "$key" ] && [ "$key" != "/" ] && [ ! -d "$key" ]; do key="$(dirname "$key")"; done + if [ "$(_session_abs_path "$mark_dir")" = "$(_session_abs_path "$HOME")" ] \ + || [ "$(git -C "$key" rev-parse --is-inside-work-tree 2>/dev/null)" = true ]; then + echo "wrap.sh session --mark-dir: '$mark_dir' is \$HOME or inside a git work tree; use a scratch directory" >&2; return 64 + fi mkdir -p "$mark_dir" 2>/dev/null && [ -d "$mark_dir" ] && [ -w "$mark_dir" ] \ || { echo "wrap.sh session --mark-dir: '$mark_dir' is not a writable directory" >&2; return 64; } mark_dir="$(cd "$mark_dir" && pwd -P)" diff --git a/tests/test-shared-lookups.sh b/tests/test-shared-lookups.sh index 84460629..51f7ba48 100644 --- a/tests/test-shared-lookups.sh +++ b/tests/test-shared-lookups.sh @@ -121,7 +121,7 @@ merged-ok lib/wrap/wrap-land.sh 2 merged-ok lib/wrap/wrap-merge.sh 6 merged-ok lib/wrap/wrap-rebase.sh 1 merged-ok lib/wrap/wrap-scan.sh 2 -merged-ok lib/wrap/wrap-session.sh 9 +merged-ok lib/wrap/wrap-session.sh 10 spec-active-ok hooks/ship-gate.sh 3 spec-active-ok lib/gate/gate-ledger.sh 3 spec-active-ok lib/gate/proof-ledger.sh 3 diff --git a/tests/test-wrap-session.sh b/tests/test-wrap-session.sh index e78f72ed..2e1a4d38 100755 --- a/tests/test-wrap-session.sh +++ b/tests/test-wrap-session.sh @@ -261,6 +261,12 @@ if [ "${1:-} ${2:-}" = "api graphql" ]; then printf '%s\n' "$GQL_STUB_JSON" exit "${GQL_STUB_RC:-0}" fi +# `pr list --head `: the PR a branch-only merge resolves to (real gh applies --jq). +if [ "${1:-} ${2:-}" = "pr list" ] && [ -n "${GQL_STUB_HEAD_PR:-}" ] && printf '%s' "$*" | grep -q -- "--head"; then + printf '%s\n' "$*" >> "$GQL_STUB_CALLS" + printf '%s\n' "$GQL_STUB_HEAD_PR" + exit 0 +fi exec "$TMPD_STUB_GH" "$@" GHGQL chmod +x "$TMPD/gh-gql/gh" @@ -399,7 +405,7 @@ chk "transcript PRs and --prs still cost one GraphQL call" "$([ "$(wc -l < "$GQL out="$(GQL_STUB_JSON="$gql_doc" gather --json --transcript "$tfile" --prs acme/ops#7 --since 1700000000 "$clone" 2>/dev/null)" jqok "an explicit --since wins and a named repo is not gathered twice" "$out" '.since == 1700000000 and (.repos | length) == 1 and ([.named_prs.rows[].ref] | index("acme/ops#7")) != null' sum="$(GQL_STUB_JSON="$gql_doc" gather --summary --transcript "$tfile" 2>/dev/null)" -chk_has "the summary names the transcript facts" "$sum" "transcript started_at_epoch=$want_epoch subagent_transcripts=1 repos=$clone_p prs=3 acted_prs=acme/ops#6190,acme/ops#7" +chk_has "the summary names the transcript facts" "$sum" "transcript started_at_epoch=$want_epoch subagent_transcripts=1 skipped_lines=0 repos=$clone_p prs=3 acted_prs=acme/ops#6190,acme/ops#7" # A repo named only by transcript text runs no repo-configured program. The control run (the # same repo named on the command line, no --transcript) proves the planted hook does fire. printf '#!/bin/sh\ntouch "%s/fsmonitor-ran"\nexit 1\n' "$TMPD" > "$TMPD/fsmon.sh"; chmod +x "$TMPD/fsmon.sh" @@ -413,6 +419,57 @@ git -C "$clone" config --unset core.fsmonitor out="$(gather --json --transcript "$TMPD/no-such.jsonl" "$clone" 2>&1)"; rc=$? chk "a missing transcript file is refused" "$([ "$rc" -eq 64 ] && echo 0 || echo 1)" +# =========================================================================== +echo "=== --transcript: cd and git -C targets, truncated lines, URL-less merges ===" +# =========================================================================== +make_clone tx2 rmain main main; make_clone tx3 rmain main main; make_clone tx4 rmain main main +tx2_p="$(cd "$TMPD/clone-tx2" && pwd -P)"; tx3_p="$(cd "$TMPD/clone-tx3" && pwd -P)"; tx4_p="$(cd "$TMPD/clone-tx4" && pwd -P)" +git -C "$TMPD/clone-tx4" remote set-url origin https://github.com/acme/merged.git +# The second and third repos appear ONLY as a `git -C` and a `cd` target, never as a cwd or an Edit path. +tg="$TMPD/projects/sess2.jsonl" +jq -cn --arg cwd "$clone_p" '{type:"user",timestamp:"2026-11-27T01:00:00Z",cwd:$cwd,message:{role:"user",content:"go"}}' > "$tg" +jq -cn --arg c "git -C \"$tx2_p\" status --short && cd $tx3_p && ls" \ + '{type:"assistant",timestamp:"2026-11-27T01:01:00Z",message:{content:[{type:"tool_use",id:"a1",name:"Bash",input:{command:$c}}]}}' >> "$tg" +out="$(gather --json --transcript "$tg" 2>/dev/null)" +jqok "a git -C target with no other mention is a gathered repo" "$out" ".transcript.repos | index(\"$tx2_p\") != null" +jqok "a cd target with no other mention is a gathered repo" "$out" ".transcript.repos | index(\"$tx3_p\") != null" + +# One truncated line between two good ones: the later repo and the later PR still count. +tt="$TMPD/projects/sess3.jsonl" +jq -cn --arg cwd "$clone_p" '{type:"user",timestamp:"2026-11-27T02:00:00Z",cwd:$cwd,message:{role:"user",content:"go"}}' > "$tt" +printf '%s\n' '{"type":"assistant","message":{"content":[{"type":"text","text":"cut off he' >> "$tt" +jq -cn --arg cwd "$tx2_p" '{type:"assistant",timestamp:"2026-11-27T02:01:00Z",cwd:$cwd,message:{content:[{type:"tool_use",id:"c1",name:"Bash",input:{command:"gh pr create --fill"}}]}}' >> "$tt" +jq -cn '{type:"user",message:{content:[{type:"tool_result",tool_use_id:"c1",content:"https://github.com/acme/ops/pull/7"}]}}' >> "$tt" +out="$(GQL_STUB_JSON="$gql_doc" gather --json --transcript "$tt" 2>/dev/null)" +jqok "a truncated line is counted, not silent" "$out" '.transcript.skipped_lines == 1' +jqok "a repo after the truncated line is still gathered" "$out" ".transcript.repos | index(\"$tx2_p\") != null" +jqok "a PR created after the truncated line is still acted" "$out" '.transcript.acted_prs == ["acme/ops#7"]' +sum="$(GQL_STUB_JSON="$gql_doc" gather --summary --transcript "$tt" 2>/dev/null)" +chk_has "the summary reports the skipped line" "$sum" "skipped_lines=1" + +# A merge with no URL and no --repo: by number in its cwd's repo, or by branch alone. +tm="$TMPD/projects/sess4.jsonl" +jq -cn --arg cwd "$tx4_p" '{type:"assistant",timestamp:"2026-11-27T03:00:00Z",cwd:$cwd,gitBranch:"feat/x",message:{content:[{type:"tool_use",id:"m1",name:"Bash",input:{command:"gh pr merge 42 --squash"}},{type:"tool_use",id:"m2",name:"Bash",input:{command:"gh pr merge --squash --delete-branch"}}]}}' > "$tm" +: > "$GQL_STUB_CALLS" +out="$(GQL_STUB_HEAD_PR=43 GQL_STUB_JSON='{"data":{"r0":{"p42":{"number":42,"title":"t","url":"u","state":"MERGED","merged":true,"mergedAt":"2026-11-27T03:00:05Z","mergeCommit":{"oid":"aaaa"},"headRefName":"feat/y","baseRefName":"main","isDraft":false,"author":{"login":"me"}},"p43":{"number":43,"title":"t","url":"u","state":"OPEN","merged":false,"mergedAt":null,"mergeCommit":null,"headRefName":"feat/x","baseRefName":"main","isDraft":false,"author":{"login":"me"}}}}}' gather --json --transcript "$tm" 2>/dev/null)" +jqok "a bare-number merge resolves against its cwd's origin" "$out" '.transcript.acted_prs | index("acme/merged#42") != null' +jqok "a branch-only merge resolves through its branch" "$out" '.transcript.acted_prs | index("acme/merged#43") != null' +jqok "both URL-less merges are read live, never taken from the transcript" "$out" '([.named_prs.rows[] | select(.ref == "acme/merged#42") | .state][0]) == "MERGED" and ([.named_prs.rows[] | select(.ref == "acme/merged#43") | .state][0]) == "OPEN"' +chk_has "the branch lookup asks for that head" "$(cat "$GQL_STUB_CALLS")" "--head feat/x" + +# =========================================================================== +echo "=== --mark-dir: never empty, never \$HOME, never inside a work tree ===" +# =========================================================================== +out="$(gather --json --mark-dir "" "$clone" 2>&1)"; rc=$? +chk "an empty --mark-dir is refused, so step 0 never silently skips" "$([ "$rc" -eq 64 ] && echo 0 || echo 1)" +out="$(gather --json --mark-dir "$clone/.marks" "$clone" 2>&1)"; rc=$? +chk "a --mark-dir inside a gathered repo is refused" "$([ "$rc" -eq 64 ] && echo 0 || echo 1)" +chk "a refused in-repo --mark-dir writes nothing" "$([ ! -e "$clone/.marks" ] && echo 0 || echo 1)" +mkdir -p "$TMPD/fakehome" +out="$(HOME="$TMPD/fakehome" gather --json --mark-dir "$TMPD/fakehome" "$clone" 2>&1)"; rc=$? +chk "a --mark-dir equal to \$HOME is refused" "$([ "$rc" -eq 64 ] && echo 0 || echo 1)" +chk_has "the refusal says why" "$out" "inside a git work tree" + echo if [ "$FAIL" -gt 0 ]; then echo "test-wrap-session: $PASS passed, $FAIL FAILED of $TOTAL" >&2; exit 1; fi echo "test-wrap-session: all $PASS passed" From afb621c746cd45d2fdca4de18e0af3fb0182e04f Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 13:07:12 +0700 Subject: [PATCH 14/19] fix(wrap): a first wrap report's NOTHING names the needs-you walk `Needs you: NOTHING` in a `## Wrap:` report now has to read `NOTHING (walked: digest replies, miner actions)` (a self-wrap: `NOTHING (walked: own replies )`); report-lint.sh refuses a bare or count-free NOTHING there. Follow-through and harvest-sweep reports are unchanged. commands/wrap.md, the guide and the quickstart show the walked form; the lint fixtures that are wrap reports carry it. ## How I verified it bash tests/test-wrap-report-lint.sh -> test-wrap-report-lint: all 164 passed bash tests/test-harvest-sweep.sh -> All harvest sweep tests passed. --- commands/wrap.md | 4 +- docs/QUICKSTART.md | 2 +- docs/guides/wrap.md | 2 +- lib/wrap/report-lint.sh | 23 +- .../harvest-sweep/report-sweep-built.md | 2 +- .../harvest-sweep/report-wrap-harvest-skip.md | 2 +- tests/test-wrap-report-lint.sh | 339 +++++++++--------- 7 files changed, 198 insertions(+), 176 deletions(-) diff --git a/commands/wrap.md b/commands/wrap.md index 5bf66597..a9f7abb9 100644 --- a/commands/wrap.md +++ b/commands/wrap.md @@ -80,14 +80,14 @@ The after seam invokes the configured `wrap.after` skill after landing. Empty is When any write step ran, run one final read-only gather over the same repos before drafting: `bin/wrap session --summary ...`. `Left alone` uses that final gather, never memory or the start snapshot. When no write ran (a dry run, or nothing to land), the start gather is the final state; do not gather again. -**Needs-you check, before writing `NOTHING`.** Walk the digest's replies and the miner's open owner actions, newest first; a self-wrap has neither, so it walks its own replies and asks this session. List every owner action they name: an ask to the operator, a blocker, a lettered `a.` `b.` item, "needs Han" or "needs you", an approval, and a merge, close, or click left to the owner. An action a later reply, the miner, or a gather row shows done is closed; leave it out. A choice the session or a worker made itself is not an owner action. Every other one goes under `Needs you`. When the newest mention leaves it open but you cannot prove it still is, list it with `check`: `a. RUN check . .` Write `NOTHING` only when this walk found no open item, never because the gather shows nothing. +**Needs-you check, before writing `NOTHING`.** Walk the digest's replies and the miner's open owner actions, newest first; a self-wrap has neither, so it walks its own replies and asks this session. List every owner action they name: an ask to the operator, a blocker, a lettered `a.` `b.` item, "needs Han" or "needs you", an approval, and a merge, close, or click left to the owner. An action a later reply, the miner, or a gather row shows done is closed; leave it out. A choice the session or a worker made itself is not an owner action. Every other one goes under `Needs you`. When the newest mention leaves it open but you cannot prove it still is, list it with `check`: `a. RUN check . .` Write `NOTHING` only when this walk found no open item, never because the gather shows nothing, and name the walk: `NOTHING (walked: digest replies, miner actions)` (a self-wrap: `NOTHING (walked: own replies )`). The lint refuses an unwalked `NOTHING`. Draft the skim-first report, write it to scratch. Run the lint before printing: `bash lib/wrap/report-lint.sh `. Fix or do what the lint names, then re-run. Never read the lint's source; when it cannot run, say so in one `SKIPPED` FYI row. The shape is: ```markdown ## Wrap: -āœ… **Needs you:** NOTHING +āœ… **Needs you:** NOTHING (walked: digest replies, miner actions) -- or -- šŸ”“ **Needs you:** a. DECIDE | RUN | REVIEW | UNBLOCK . . . diff --git a/docs/QUICKSTART.md b/docs/QUICKSTART.md index f0a96505..207509e0 100644 --- a/docs/QUICKSTART.md +++ b/docs/QUICKSTART.md @@ -88,7 +88,7 @@ After the PR is up, run `/kit:wrap`. It flips board rows, merges your own green ``` ## Wrap: -āœ… **Needs you:** NOTHING +āœ… **Needs you:** NOTHING (walked: digest 4 replies, miner 2 actions) **What happened** **Shipped** diff --git a/docs/guides/wrap.md b/docs/guides/wrap.md index 82c4ca16..04dcacbd 100644 --- a/docs/guides/wrap.md +++ b/docs/guides/wrap.md @@ -72,7 +72,7 @@ The report that `/kit:wrap` prints leads with the one question that matters: ``` ## Wrap: -āœ… **Needs you:** NOTHING +āœ… **Needs you:** NOTHING (walked: digest 4 replies, miner 2 actions) **What happened** **Shipped** | Repo | PR | Merge | Deploy | **Left alone:** diff --git a/lib/wrap/report-lint.sh b/lib/wrap/report-lint.sh index 41bda553..17c0dbb0 100755 --- a/lib/wrap/report-lint.sh +++ b/lib/wrap/report-lint.sh @@ -78,6 +78,8 @@ sweep_report=0 first_h2="$(printf '%s\n' "$input" | grep -m1 '^## ' || true)" case "$first_h2" in '## Follow-through:'*) follow_report=1 ;; esac case "$first_h2" in '## Harvest sweep:'*) sweep_report=1 ;; esac +wrap_report=0 +case "$first_h2" in '## Wrap:'*) wrap_report=1 ;; esac # PR numbers named by `Needs you` items that open with REVIEW, space-separated, filled by the # walk below. A full-lane build in a follow-through report must name one of them. @@ -92,7 +94,16 @@ in_block=0 while IFS= read -r line; do lineno=$((lineno + 1)) case "$line" in - *'**Needs you:**'*) in_block=1; continue ;; + *'**Needs you:**'*) + # A first wrap report's NOTHING names what the needs-you walk read, so an unwalked + # NOTHING cannot pass: `NOTHING (walked: digest 4 replies, miner 2 actions)`. + if [ "$wrap_report" = 1 ] && printf '%s' "$line" | grep -q 'NOTHING' \ + && ! printf '%s' "$line" | grep -qE 'NOTHING \(walked: [^)]*[0-9][^)]*\)'; then + echo "line ${lineno}: Needs you says NOTHING without naming the walk; write NOTHING (walked: digest replies, miner actions)" >&2 + echo " ${line}" >&2 + findings=$((findings + 1)) + fi + in_block=1; continue ;; esac [ "$in_block" = 1 ] || continue # Any other bold section header closes the block. @@ -505,11 +516,11 @@ while IFS= read -r _p_line; do case "$_p_line" in '```'*) _p_fence=$((1 - _p_fence)); continue ;; esac [ "$_p_fence" = 1 ] && continue case "$_p_line" in - *'**Needs you:**'*) _p_sect=needs; continue ;; - '**What happened**'*) _p_sect=what; continue ;; - '**Left alone:**'*) _p_sect=left; continue ;; - '**FYI:**'*) _p_sect=fyi; continue ;; - '**Built:**'*) _p_sect=built ;; + *'**Needs you:**'*) _p_sect="needs"; continue ;; + '**What happened**'*) _p_sect="what"; continue ;; + '**Left alone:**'*) _p_sect="left"; continue ;; + '**FYI:**'*) _p_sect="fyi"; continue ;; + '**Built:**'*) _p_sect="built" ;; '**'*'**'*) _p_sect=""; continue ;; esac _p_text="" diff --git a/tests/fixtures/harvest-sweep/report-sweep-built.md b/tests/fixtures/harvest-sweep/report-sweep-built.md index 11edce97..cd28eaf4 100644 --- a/tests/fixtures/harvest-sweep/report-sweep-built.md +++ b/tests/fixtures/harvest-sweep/report-sweep-built.md @@ -1,6 +1,6 @@ ## Harvest sweep: run-2000000001 -āœ… **Needs you:** NOTHING +āœ… **Needs you:** NOTHING (walked: digest 2 replies, miner 0 actions) **What happened** - read 6 sessions across 2 sources, staged 2 learnings, reported 2 candidates. diff --git a/tests/fixtures/harvest-sweep/report-wrap-harvest-skip.md b/tests/fixtures/harvest-sweep/report-wrap-harvest-skip.md index d0486c36..c69ce799 100644 --- a/tests/fixtures/harvest-sweep/report-wrap-harvest-skip.md +++ b/tests/fixtures/harvest-sweep/report-wrap-harvest-skip.md @@ -1,6 +1,6 @@ ## Wrap: landing with the sweep owning distill -āœ… **Needs you:** NOTHING +āœ… **Needs you:** NOTHING (walked: digest 2 replies, miner 0 actions) **Built:** SKIPPED: distill runs in the harvest sweep diff --git a/tests/test-wrap-report-lint.sh b/tests/test-wrap-report-lint.sh index 41916a17..046e5a8c 100755 --- a/tests/test-wrap-report-lint.sh +++ b/tests/test-wrap-report-lint.sh @@ -18,21 +18,32 @@ LINT="$KIT_DIR/lib/wrap/report-lint.sh" # rule gets its own cases further down. _report() { printf '## Wrap: t\n\n%s\n\n**Built:** NOTHING: no candidates\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- %s\n' "$1" "${2:-body}"; } +# The needs-you walk: a first wrap report's NOTHING names what was walked. +out="$(_report 'āœ… **Needs you:** NOTHING' | bash "$LINT" 2>&1)"; rc=$? +chk "a bare NOTHING in a wrap report fails the lint" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" +chk_has "the finding names the walk to write" "$out" "NOTHING (walked: digest replies, miner actions)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: nothing)' | bash "$LINT" 2>&1)"; rc=$? +chk "a walk with no count fails the lint" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: own replies 6)' | bash "$LINT" 2>&1)"; rc=$? +chk "a self-wrap walk passes" "$rc" +out="$(_report 'āœ… **Needs you:** NOTHING' | sed '1s/^## Wrap:.*/## Follow-through: t/' | bash "$LINT" 2>&1)"; rc=$? +chk_no "a follow-through report keeps its bare NOTHING" "$out" "without naming the walk" + out="$(_report 'šŸ”“ **Needs you:** a. REVIEW then merge #523. Say go and I merge it.' | bash "$LINT" 2>&1)"; rc=$? -chk "the original defect fails the lint" "$([ "$rc" -eq 1 ]; echo $?)" +chk "the original defect fails the lint" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the finding names the offending item" "$out" "asks permission instead of naming a blocker" -out="$(_report 'āœ… **Needs you:** NOTHING' 'say go and I merge it' | bash "$LINT" 2>&1)"; rc=$? -chk "NOTHING passes, and What happened is never judged" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' 'say go and I merge it' | bash "$LINT" 2>&1)"; rc=$? +chk "NOTHING passes, and What happened is never judged" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" out="$(_report 'šŸ”“ **Needs you:** a. UNBLOCK the deploy. It is blocked on a credential only you can read.' | bash "$LINT" 2>&1)"; rc=$? -chk "a real blocker passes" "$([ "$rc" -eq 0 ]; echo $?)" +chk "a real blocker passes" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" out="$(_report 'šŸ”“ **Needs you:** a. RUN gh pr merge 12 --squash.' | bash "$LINT" 2>&1)"; rc=$? -chk "a self-runnable command with no blocker warns, does not fail" "$([ "$rc" -eq 0 ]; echo $?)" +chk "a self-runnable command with no blocker warns, does not fail" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" chk_has "the warn names the command class" "$out" "names a command the kit can run" out="$(_report 'šŸ”“ **Needs you:** @@ -40,93 +51,93 @@ a. RUN gh pr merge 12 once security signs off; it is blocked on their approval.' chk_no "a stated blocker clears the warn" "$out" "names a command the kit can run" out="$(printf 'no needs-you section at all\n\n**Built:** SKIPPED: build_candidates knob is false\n\n**Seam:** SKIPPED: no seam\n' | bash "$LINT" 2>&1)"; rc=$? -chk "a report with no Needs you block is clean" "$([ "$rc" -eq 0 ]; echo $?)" +chk "a report with no Needs you block is clean" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" # The Built rule itself. commands/wrap.md: step 7b owes exactly one of built / NOTHING / # SKIPPED, so a skipped 7b can never read as an empty one. The lint shipped with no test. out="$(printf 'no needs-you section at all\n\n**Seam:** NOTHING: no seam configured\n' | bash "$LINT" 2>&1)"; rc=$? -chk "a report with no Built line fails" "$([ "$rc" -eq 1 ]; echo $?)" +chk "a report with no Built line fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the finding names step 7b" "$out" "step 7b (build the candidates) owes an outcome" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's/^\*\*Built:\*\* .*/**Built:**/' | bash "$LINT" 2>&1)"; rc=$? -chk "an empty Built line fails" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's/^\*\*Built:\*\* .*/**Built:**/' | bash "$LINT" 2>&1)"; rc=$? +chk "an empty Built line fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the finding says it is empty" "$out" "is empty; name what was built" # The three states must stay distinguishable, and a non-empty line must name the home it # joins. `SKIPPED: nothing to build` (two states in one) appeared thirteen times in two weeks # of real reports; `Built: @ ` with no ENHANCE/NEW was every "built" line in the # same window, and each one was the session's own deliverable, not a 7b candidate. -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** lib/wrap/report-lint.sh @ abc1234|' | bash "$LINT" 2>&1)"; rc=$? -chk "a Built line that is only a path and a commit fails" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** lib/wrap/report-lint.sh @ abc1234|' | bash "$LINT" 2>&1)"; rc=$? +chk "a Built line that is only a path and a commit fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the finding asks for the ENHANCE or NEW token" "$out" "no ENHANCE or NEW (precedent: ...) token" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** SKIPPED: nothing to build|' | bash "$LINT" 2>&1)"; rc=$? -chk "SKIPPED: nothing to build fails (an empty scan is NOTHING)" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** SKIPPED: nothing to build|' | bash "$LINT" 2>&1)"; rc=$? +chk "SKIPPED: nothing to build fails (an empty scan is NOTHING)" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the finding names the two-states-in-one shape" "$out" "an empty scan is 'NOTHING: no candidates', not a skip" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** BUILT wake-probe ENHANCE tools/alert-triage: tests/live/wake-probe after the touch probe (a1b2c3d)|' | bash "$LINT" 2>&1)"; rc=$? -chk "an ENHANCE line naming the home and insertion point passes" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** BUILT wake-probe ENHANCE tools/alert-triage: tests/live/wake-probe after the touch probe (a1b2c3d)|' | bash "$LINT" 2>&1)"; rc=$? +chk "an ENHANCE line naming the home and insertion point passes" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** REPORTED cron-fire NEW (precedent: nothing matched): tools/cron-fire (reported: needs a spec)|' | bash "$LINT" 2>&1)"; rc=$? -chk "a NEW line carrying the precedent miss passes" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** REPORTED cron-fire NEW (precedent: nothing matched): tools/cron-fire (reported: needs a spec)|' | bash "$LINT" 2>&1)"; rc=$? +chk "a NEW line carrying the precedent miss passes" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** SKIPPED: build_candidates knob is false|' | bash "$LINT" 2>&1)"; rc=$? -chk "a real SKIPPED reason passes" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** SKIPPED: build_candidates knob is false|' | bash "$LINT" 2>&1)"; rc=$? +chk "a real SKIPPED reason passes" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" # An operator's kit.toml can set the distill switch off (landing-only), so this report shape # still occurs: both lines SKIPPED with the switch as the reason, and the lint must take it as # a real skip. -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** SKIPPED: distill off|; s|^\*\*Seam:\*\* .*|**Seam:** SKIPPED: distill off|' | bash "$LINT" 2>&1)"; rc=$? -chk "Built and Seam both SKIPPED: distill off passes" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** SKIPPED: distill off|; s|^\*\*Seam:\*\* .*|**Seam:** SKIPPED: distill off|' | bash "$LINT" 2>&1)"; rc=$? +chk "Built and Seam both SKIPPED: distill off passes" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" # The lane suffix. commands/wrap.md step 7b routes every candidate through # lib/classify/lane-classify.sh: a tiny-lane candidate is built here and carries the check # that proved it, anything heavier is reported with a one-line why. Both shapes append to the # same line, so the ENHANCE/NEW token must survive the suffix, and the suffix alone must never # stand in for the token. -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** BUILT wake-probe ENHANCE tools/alert-triage: tests/live/wake-probe after the touch probe (lane=tiny, verified: bash tests/test-alert.sh, a1b2c3d)|' | bash "$LINT" 2>&1)"; rc=$? -chk "an ENHANCE line carrying lane=tiny and its check passes" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** BUILT wake-probe ENHANCE tools/alert-triage: tests/live/wake-probe after the touch probe (lane=tiny, verified: bash tests/test-alert.sh, a1b2c3d)|' | bash "$LINT" 2>&1)"; rc=$? +chk "an ENHANCE line carrying lane=tiny and its check passes" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** REPORTED cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=normal, reported: owes a review, too big for session close)|' | bash "$LINT" 2>&1)"; rc=$? -chk "a NEW line carrying lane=normal and its reported why passes" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** REPORTED cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=normal, reported: owes a review, too big for session close)|' | bash "$LINT" 2>&1)"; rc=$? +chk "a NEW line carrying lane=normal and its reported why passes" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** REPORTED cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=normal, reported: build_candidates off)|' | bash "$LINT" 2>&1)"; rc=$? -chk "the knob-false shape, reported with the knob as the why, passes" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** REPORTED cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=normal, reported: build_candidates off)|' | bash "$LINT" 2>&1)"; rc=$? +chk "the knob-false shape, reported with the knob as the why, passes" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** lib/wrap/report-lint.sh (lane=tiny, verified: bash tests/test-wrap.sh, abc1234)|' | bash "$LINT" 2>&1)"; rc=$? -chk "a lane suffix with no ENHANCE or NEW still fails" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** lib/wrap/report-lint.sh (lane=tiny, verified: bash tests/test-wrap.sh, abc1234)|' | bash "$LINT" 2>&1)"; rc=$? +chk "a lane suffix with no ENHANCE or NEW still fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the finding still asks for the ENHANCE or NEW token" "$out" "no ENHANCE or NEW (precedent: ...) token" # The verdict. Every candidate opens with BUILT, REPORTED, or NOTE; a line without one # reads as built when it may only have been reported or noted. -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** wake-probe ENHANCE tools/alert-triage: tests/live/wake-probe after the touch probe (lane=tiny, verified: bash tests/test-alert.sh, a1b2c3d)|' | bash "$LINT" 2>&1)"; rc=$? -chk "a candidate with no leading verdict fails" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** wake-probe ENHANCE tools/alert-triage: tests/live/wake-probe after the touch probe (lane=tiny, verified: bash tests/test-alert.sh, a1b2c3d)|' | bash "$LINT" 2>&1)"; rc=$? +chk "a candidate with no leading verdict fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the finding names the three verdicts" "$out" "BUILT, REPORTED, or NOTE" # STAGED and FILED are retired: step 7b never writes a staging block or mints a board row. -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** STAGED cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=normal, staged + goal drafted: .claude/goals/cron-fire.md)|' | bash "$LINT" 2>&1)"; rc=$? -chk "a STAGED verdict fails, staging is retired" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** STAGED cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=normal, staged + goal drafted: .claude/goals/cron-fire.md)|' | bash "$LINT" 2>&1)"; rc=$? +chk "a STAGED verdict fails, staging is retired" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the finding names the retired verdict" "$out" "uses a retired verdict" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** FILED cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=full, filed: acme-app ID-901, goal drafted: .claude/goals/cron-fire.md)|' | bash "$LINT" 2>&1)"; rc=$? -chk "a FILED verdict fails, wrap never mints a board row" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** FILED cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=full, filed: acme-app ID-901, goal drafted: .claude/goals/cron-fire.md)|' | bash "$LINT" 2>&1)"; rc=$? +chk "a FILED verdict fails, wrap never mints a board row" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the FILED finding names the retired verdict" "$out" "uses a retired verdict" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** NOTE remerge ENHANCE dwarves-kit bin/wrap merge: PROSE-ONLY: the verb already re-merges under the union driver, nothing was missing, memory note written|' | bash "$LINT" 2>&1)"; rc=$? -chk "a NOTE verdict on a prose-only candidate passes" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** NOTE remerge ENHANCE dwarves-kit bin/wrap merge: PROSE-ONLY: the verb already re-merges under the union driver, nothing was missing, memory note written|' | bash "$LINT" 2>&1)"; rc=$? +chk "a NOTE verdict on a prose-only candidate passes" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" # A precedent hit that already does the whole job. Nothing is missing in the tool; the path # to it is. REPORTED gave step 10 nothing to build, so the session after hand-rolled the same # curl calls again. The item closes as NOTE with the pointer written in-session. -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** REPORTED discord-readback ENHANCE tools/discord-pull: its --since, --channel and --embeds flags already read a channel latest embeds, nothing missing (lane=tiny, reported: the existing tool already covers it; this session wrote its own curl calls instead)|' | bash "$LINT" 2>&1)"; rc=$? -chk "a REPORTED item whose tool already covers it fails" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** REPORTED discord-readback ENHANCE tools/discord-pull: its --since, --channel and --embeds flags already read a channel latest embeds, nothing missing (lane=tiny, reported: the existing tool already covers it; this session wrote its own curl calls instead)|' | bash "$LINT" 2>&1)"; rc=$? +chk "a REPORTED item whose tool already covers it fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the finding says close it as NOTE with the pointer" "$out" "close it as NOTE" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** REPORTED eb-sign ENHANCE _meta/eb-post: --stream signs and posts (lane=tiny, reported: Nothing Missing in the tool)|' | bash "$LINT" 2>&1)"; rc=$? -chk "the covered-reason match is case-insensitive" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** REPORTED eb-sign ENHANCE _meta/eb-post: --stream signs and posts (lane=tiny, reported: Nothing Missing in the tool)|' | bash "$LINT" 2>&1)"; rc=$? +chk "the covered-reason match is case-insensitive" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** NOTE discord-readback ENHANCE tools/discord-pull: covered, pointer added at skills/discord-post/SKILL.md (lane=tiny, verified: grep -q discord-pull skills/discord-post/SKILL.md, a1b2c3d)|' | bash "$LINT" 2>&1)"; rc=$? -chk "a covered precedent closed as NOTE with its pointer passes" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** NOTE discord-readback ENHANCE tools/discord-pull: covered, pointer added at skills/discord-post/SKILL.md (lane=tiny, verified: grep -q discord-pull skills/discord-post/SKILL.md, a1b2c3d)|' | bash "$LINT" 2>&1)"; rc=$? +chk "a covered precedent closed as NOTE with its pointer passes" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" # The lane closure rule. `wrap.build_lanes` lets an operator list heavier lanes for step 7b to # build inline, so `lane=normal`, `lane=bug` and `lane=backfill` are legal on a verified item @@ -134,45 +145,45 @@ chk "a covered precedent closed as NOTE with its pointer passes" "$([ "$rc" -eq # the pairing: a lane token says the candidate was sized and nothing about what became of it, # so every item naming a lane owes `verified:` or `reported:`. The retired closures # (`staged`, `filed:`, `capture failed:`) no longer close a lane. -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** BUILT wake-probe ENHANCE tools/alert-triage: tests/live/wake-probe after the touch probe (lane=normal, verified: bash tests/test-alert.sh, #418)|' | bash "$LINT" 2>&1)"; rc=$? -chk "an ENHANCE line carrying lane=normal and its check passes" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** BUILT wake-probe ENHANCE tools/alert-triage: tests/live/wake-probe after the touch probe (lane=normal, verified: bash tests/test-alert.sh, #418)|' | bash "$LINT" 2>&1)"; rc=$? +chk "an ENHANCE line carrying lane=normal and its check passes" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** BUILT cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=bug, verified: bash tests/test-cron.sh, a1b2c3d)|' | bash "$LINT" 2>&1)"; rc=$? -chk "a NEW line carrying lane=bug and its check passes" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** BUILT cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=bug, verified: bash tests/test-cron.sh, a1b2c3d)|' | bash "$LINT" 2>&1)"; rc=$? +chk "a NEW line carrying lane=bug and its check passes" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** BUILT cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=backfill, verified: bash tests/test-cron.sh, b2c3d4e)|' | bash "$LINT" 2>&1)"; rc=$? -chk "a NEW line carrying lane=backfill and its check passes" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** BUILT cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=backfill, verified: bash tests/test-cron.sh, b2c3d4e)|' | bash "$LINT" 2>&1)"; rc=$? +chk "a NEW line carrying lane=backfill and its check passes" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** REPORTED cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=full, reported: owes a spec and a review)|' | bash "$LINT" 2>&1)"; rc=$? -chk "a full lane reported with its why passes" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** REPORTED cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=full, reported: owes a spec and a review)|' | bash "$LINT" 2>&1)"; rc=$? +chk "a full lane reported with its why passes" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** REPORTED cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=full, filed: acme-app ID-901)|' | bash "$LINT" 2>&1)"; rc=$? -chk "a retired filed: closure no longer closes a lane" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** REPORTED cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=full, filed: acme-app ID-901)|' | bash "$LINT" 2>&1)"; rc=$? +chk "a retired filed: closure no longer closes a lane" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the retired closure reads as no closure" "$out" "names a lane with no closure" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** REPORTED cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=normal, staged: build_candidates off)|' | bash "$LINT" 2>&1)"; rc=$? -chk "a retired staged closure no longer closes a lane" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** REPORTED cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=normal, staged: build_candidates off)|' | bash "$LINT" 2>&1)"; rc=$? +chk "a retired staged closure no longer closes a lane" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** BUILT cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=full, verified: bash tests/test-cron.sh, a1b2c3d)|' | bash "$LINT" 2>&1)"; rc=$? -chk "a full lane closed as built fails, full is never built at session close" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** BUILT cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=full, verified: bash tests/test-cron.sh, a1b2c3d)|' | bash "$LINT" 2>&1)"; rc=$? +chk "a full lane closed as built fails, full is never built at session close" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the finding names the full-lane rule" "$out" "closes a full-lane candidate as built" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** BUILT cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=tiny, reported: nope)|' | bash "$LINT" 2>&1)"; rc=$? -chk "BUILT closed as reported fails" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** BUILT cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=tiny, reported: nope)|' | bash "$LINT" 2>&1)"; rc=$? +chk "BUILT closed as reported fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the finding names the verdict and closure mismatch" "$out" "pairs its verdict with the wrong closure" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** REPORTED cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=normal, verified: bash tests/test-cron.sh, a1b2c3d)|' | bash "$LINT" 2>&1)"; rc=$? -chk "REPORTED closed as verified fails" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** REPORTED cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=normal, verified: bash tests/test-cron.sh, a1b2c3d)|' | bash "$LINT" 2>&1)"; rc=$? +chk "REPORTED closed as verified fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** REPORTED cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=normal, unreported: x)|' | bash "$LINT" 2>&1)"; rc=$? -chk "an unanchored closure token (unreported:) does not close a lane" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** REPORTED cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=normal, unreported: x)|' | bash "$LINT" 2>&1)"; rc=$? +chk "an unanchored closure token (unreported:) does not close a lane" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** REPORTED cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=normal)|' | bash "$LINT" 2>&1)"; rc=$? -chk "a lane with neither a check nor a reported why fails" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** REPORTED cron-fire NEW (precedent: nothing matched): tools/cron-fire (lane=normal)|' | bash "$LINT" 2>&1)"; rc=$? +chk "a lane with neither a check nor a reported why fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the finding names the missing closure" "$out" "names a lane with no closure" -out="$(printf 'āœ… **Needs you:** NOTHING\n\n**Built:**\n- BUILT alpha ENHANCE tools/x: file.sh (lane=normal, verified: bash tests/test-x.sh, #12)\n- REPORTED beta NEW (precedent: nothing matched): tools/beta (lane=bug)\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- body\n' | bash "$LINT" 2>&1)"; rc=$? -chk "one unclosed lane among good bullets fails" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(printf 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)\n\n**Built:**\n- BUILT alpha ENHANCE tools/x: file.sh (lane=normal, verified: bash tests/test-x.sh, #12)\n- REPORTED beta NEW (precedent: nothing matched): tools/beta (lane=bug)\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- body\n' | bash "$LINT" 2>&1)"; rc=$? +chk "one unclosed lane among good bullets fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the finding names the offending bullet by index" "$out" "item 2" chk_has "commands/wrap.md classifies each candidate's lane" "$(cat "$KIT_DIR/commands/wrap.md")" "lib/classify/lane-classify.sh risk" @@ -191,24 +202,24 @@ chk_no "kit.toml dropped the staged-exclusion form" "$(cat "$KIT_DIR/kit.toml")" # line. Added after a real report crammed three candidates onto one unreadable line. Each # bullet owes the same ENHANCE/NEW token as the inline form, checked per bullet, so one bare # item among several good ones cannot hide the way it did when the whole line was one string. -out="$(printf 'āœ… **Needs you:** NOTHING\n\n**Built:**\n- REPORTED untracked-blocks-ff-pull NEW (precedent: nothing matched): dwarvesf/dwarves-kit lib/wrap, the pull path in wrap apply (reported: needs a spec)\n- BUILT mini-script-run-loop ENHANCE acme-app tools/mac-mini-substrate/mini-run (no change needed, precedent hit is the helper itself)\n- BUILT sandbox-overlap-probe ENHANCE dwarvesf/foundation-ops fleet/knowledge-guard (already homed as OPS-16)\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- body\n' | bash "$LINT" 2>&1)"; rc=$? -chk "a three-bullet Built list passes" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(printf 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)\n\n**Built:**\n- REPORTED untracked-blocks-ff-pull NEW (precedent: nothing matched): dwarvesf/dwarves-kit lib/wrap, the pull path in wrap apply (reported: needs a spec)\n- BUILT mini-script-run-loop ENHANCE acme-app tools/mac-mini-substrate/mini-run (no change needed, precedent hit is the helper itself)\n- BUILT sandbox-overlap-probe ENHANCE dwarvesf/foundation-ops fleet/knowledge-guard (already homed as OPS-16)\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- body\n' | bash "$LINT" 2>&1)"; rc=$? +chk "a three-bullet Built list passes" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" -out="$(printf 'āœ… **Needs you:** NOTHING\n\n**Built:**\n- BUILT alpha ENHANCE tools/x: file.sh (abc1234)\n- lib/wrap/report-lint.sh @ def5678\n- REPORTED gamma NEW (precedent: nothing matched): tools/gamma (reported: needs a spec)\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- body\n' | bash "$LINT" 2>&1)"; rc=$? -chk "a list with one bare path-and-commit bullet fails" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(printf 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)\n\n**Built:**\n- BUILT alpha ENHANCE tools/x: file.sh (abc1234)\n- lib/wrap/report-lint.sh @ def5678\n- REPORTED gamma NEW (precedent: nothing matched): tools/gamma (reported: needs a spec)\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- body\n' | bash "$LINT" 2>&1)"; rc=$? +chk "a list with one bare path-and-commit bullet fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the finding names the offending bullet by index" "$out" "bullet 2" chk_has "the finding quotes the bare bullet" "$out" "lib/wrap/report-lint.sh @ def5678" -out="$(printf 'āœ… **Needs you:** NOTHING\n\n**Built:**\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- body\n' | bash "$LINT" 2>&1)"; rc=$? -chk "a bare Built header with no bullets and no inline content fails" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(printf 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)\n\n**Built:**\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- body\n' | bash "$LINT" 2>&1)"; rc=$? +chk "a bare Built header with no bullets and no inline content fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the finding says it is empty" "$out" "is empty" -out="$(printf 'āœ… **Needs you:** NOTHING\n\n**Built:** NOTHING: no candidates\n- BUILT stray ENHANCE tools/x: file.sh (abc1234)\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- body\n' | bash "$LINT" 2>&1)"; rc=$? -chk "NOTHING inline mixed with bullets fails, the two grammars never combine" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(printf 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)\n\n**Built:** NOTHING: no candidates\n- BUILT stray ENHANCE tools/x: file.sh (abc1234)\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- body\n' | bash "$LINT" 2>&1)"; rc=$? +chk "NOTHING inline mixed with bullets fails, the two grammars never combine" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the finding names the mixed-grammar shape" "$out" "both inline content and bullets" -out="$(printf 'āœ… **Needs you:** NOTHING\n\n**Built:** NOTHING: no candidates\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- body\n' | bash "$LINT" 2>&1)"; rc=$? -chk "NOTHING inline alone still passes" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(printf 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)\n\n**Built:** NOTHING: no candidates\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- body\n' | bash "$LINT" 2>&1)"; rc=$? +chk "NOTHING inline alone still passes" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" # The prose rule. `bin/precedent` indexes memory notes and research files as hit kinds, so a # step 7b whose top hit is a note turns a build into a write and still carries the ENHANCE @@ -216,30 +227,30 @@ chk "NOTHING inline alone still passes" "$([ "$rc" -eq 0 ]; echo $?)" # production deploy, produced two memory notes and one research note and zero mechanism, and # the report linted clean. The same precedent output named `lib/wrap/wrap.sh` one line below # the note, and the real fix landed there later: a code home beats a prose home. -out="$(printf 'āœ… **Needs you:** NOTHING\n\n**Built:**\n- BUILT pull-lesson ENHANCE acme-app .claude/memory/ff-pull-trap.md (abc1234)\n- BUILT pull-context ENHANCE acme-app research/2026-09-10-ff-pull.md (def5678)\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- body\n' | bash "$LINT" 2>&1)"; rc=$? -chk "an all-prose Built list fails" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(printf 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)\n\n**Built:**\n- BUILT pull-lesson ENHANCE acme-app .claude/memory/ff-pull-trap.md (abc1234)\n- BUILT pull-context ENHANCE acme-app research/2026-09-10-ff-pull.md (def5678)\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- body\n' | bash "$LINT" 2>&1)"; rc=$? +chk "an all-prose Built list fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the finding names the prose rule" "$out" "a precedent hit on a note is not a build" chk_has "the finding says the code home wins" "$out" "the code home wins" -out="$(printf 'āœ… **Needs you:** NOTHING\n\n**Built:**\n- BUILT pull-lesson ENHANCE acme-app .claude/memory/ff-pull-trap.md (abc1234)\n- BUILT pull-context ENHANCE acme-app research/2026-09-10-ff-pull.md (def5678)\n- PROSE-ONLY: the call is one human judgment per run, no mechanism fits it\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- body\n' | bash "$LINT" 2>&1)"; rc=$? -chk "the same all-prose Built passes with a real PROSE-ONLY reason" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(printf 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)\n\n**Built:**\n- BUILT pull-lesson ENHANCE acme-app .claude/memory/ff-pull-trap.md (abc1234)\n- BUILT pull-context ENHANCE acme-app research/2026-09-10-ff-pull.md (def5678)\n- PROSE-ONLY: the call is one human judgment per run, no mechanism fits it\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- body\n' | bash "$LINT" 2>&1)"; rc=$? +chk "the same all-prose Built passes with a real PROSE-ONLY reason" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" -out="$(printf 'āœ… **Needs you:** NOTHING\n\n**Built:**\n- BUILT pull-lesson ENHANCE acme-app .claude/memory/ff-pull-trap.md (abc1234)\n- PROSE-ONLY: none\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- body\n' | bash "$LINT" 2>&1)"; rc=$? -chk "a too-short PROSE-ONLY reason cannot silence the rule" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(printf 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)\n\n**Built:**\n- BUILT pull-lesson ENHANCE acme-app .claude/memory/ff-pull-trap.md (abc1234)\n- PROSE-ONLY: none\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- body\n' | bash "$LINT" 2>&1)"; rc=$? +chk "a too-short PROSE-ONLY reason cannot silence the rule" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the finding still names the prose rule" "$out" "a precedent hit on a note is not a build" -out="$(printf 'āœ… **Needs you:** NOTHING\n\n**Built:**\n- BUILT pull-guard ENHANCE dwarvesf/dwarves-kit lib/wrap/wrap.sh (abc1234)\n- BUILT pull-lesson ENHANCE acme-app .claude/memory/ff-pull-trap.md (def5678)\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- body\n' | bash "$LINT" 2>&1)"; rc=$? -chk "a mixed Built passes, because something was built" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(printf 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)\n\n**Built:**\n- BUILT pull-guard ENHANCE dwarvesf/dwarves-kit lib/wrap/wrap.sh (abc1234)\n- BUILT pull-lesson ENHANCE acme-app .claude/memory/ff-pull-trap.md (def5678)\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- body\n' | bash "$LINT" 2>&1)"; rc=$? +chk "a mixed Built passes, because something was built" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** BUILT pull-lesson ENHANCE acme-app .claude/memory/ff-pull-trap.md (abc1234)|' | bash "$LINT" 2>&1)"; rc=$? -chk "an inline Built naming a single memory note fails" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** BUILT pull-lesson ENHANCE acme-app .claude/memory/ff-pull-trap.md (abc1234)|' | bash "$LINT" 2>&1)"; rc=$? +chk "an inline Built naming a single memory note fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the inline finding names the prose rule" "$out" "a precedent hit on a note is not a build" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** BUILT pull-lesson ENHANCE acme-app .claude/memory/ff-pull-trap.md (abc1234) PROSE-ONLY: the pull path already guards itself, only the trap was new|' | bash "$LINT" 2>&1)"; rc=$? -chk "an inline PROSE-ONLY token with a real reason passes" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** BUILT pull-lesson ENHANCE acme-app .claude/memory/ff-pull-trap.md (abc1234) PROSE-ONLY: the pull path already guards itself, only the trap was new|' | bash "$LINT" 2>&1)"; rc=$? +chk "an inline PROSE-ONLY token with a real reason passes" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Built:\*\* .*|**Built:** BUILT pull-guard ENHANCE dwarvesf/dwarves-kit lib/wrap/wrap.sh (abc1234)|' | bash "$LINT" 2>&1)"; rc=$? -chk "an inline Built naming a code path still passes" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Built:\*\* .*|**Built:** BUILT pull-guard ENHANCE dwarvesf/dwarves-kit lib/wrap/wrap.sh (abc1234)|' | bash "$LINT" 2>&1)"; rc=$? +chk "an inline Built naming a code path still passes" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" # The harness-shape check: a `NEW (precedent: nothing matched)` candidate that turns out to # speak CDP already has a home (browser-harness-js learnings), so it warns instead of passing @@ -247,69 +258,69 @@ chk "an inline Built naming a code path still passes" "$([ "$rc" -eq 0 ]; echo $ HARNESS_FIX="$TMPD/harness-fixture"; mkdir -p "$HARNESS_FIX" printf "await session.Runtime.evaluate({ expression: '1+1' });\n" > "$HARNESS_FIX/probe.js" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed "s|^\*\*Built:\*\* .*|**Built:** REPORTED site-probe NEW (precedent: nothing matched): ${HARNESS_FIX} (reported: needs a spec)|" | bash "$LINT" 2>&1)"; rc=$? -chk "a NEW item whose files call the CDP harness warns, not fails" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed "s|^\*\*Built:\*\* .*|**Built:** REPORTED site-probe NEW (precedent: nothing matched): ${HARNESS_FIX} (reported: needs a spec)|" | bash "$LINT" 2>&1)"; rc=$? +chk "a NEW item whose files call the CDP harness warns, not fails" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" chk_has "the warn names the harness home" "$out" "browser-harness-js skills/cdp/learnings" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed "s|^\*\*Built:\*\* .*|**Built:** BUILT wake-probe ENHANCE tools/alert-triage: ${HARNESS_FIX} (a1b2c3d)|" | bash "$LINT" 2>&1)"; rc=$? -chk "an ENHANCE item is never checked for harness shape, even over the same CDP content" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed "s|^\*\*Built:\*\* .*|**Built:** BUILT wake-probe ENHANCE tools/alert-triage: ${HARNESS_FIX} (a1b2c3d)|" | bash "$LINT" 2>&1)"; rc=$? +chk "an ENHANCE item is never checked for harness shape, even over the same CDP content" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" chk_no "no harness warn on an ENHANCE line" "$out" "browser-harness-js skills/cdp/learnings" # The harness-shape check on a LIST-form bullet: the same token match, on a `- ` line. LIST_HARNESS_FIX="$TMPD/harness-fixture-list"; mkdir -p "$LIST_HARNESS_FIX" printf "await session.Runtime.evaluate({ expression: '1+1' });\n" > "$LIST_HARNESS_FIX/probe.js" -out="$(printf 'āœ… **Needs you:** NOTHING\n\n**Built:**\n- REPORTED site-probe NEW (precedent: nothing matched): %s (reported: needs a spec)\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- body\n' "$LIST_HARNESS_FIX" | bash "$LINT" 2>&1)"; rc=$? -chk "a NEW bullet whose files call the CDP harness warns, not fails" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(printf 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)\n\n**Built:**\n- REPORTED site-probe NEW (precedent: nothing matched): %s (reported: needs a spec)\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- body\n' "$LIST_HARNESS_FIX" | bash "$LINT" 2>&1)"; rc=$? +chk "a NEW bullet whose files call the CDP harness warns, not fails" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" chk_has "the warn names the harness home for a bullet item" "$out" "browser-harness-js skills/cdp/learnings" printf 'echo "plain shell content, no CDP calls here"\n' > "$HARNESS_FIX/probe.js" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed "s|^\*\*Built:\*\* .*|**Built:** REPORTED site-probe NEW (precedent: nothing matched): ${HARNESS_FIX} (reported: needs a spec)|" | bash "$LINT" 2>&1)"; rc=$? -chk "the same NEW path with plain content does not warn" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed "s|^\*\*Built:\*\* .*|**Built:** REPORTED site-probe NEW (precedent: nothing matched): ${HARNESS_FIX} (reported: needs a spec)|" | bash "$LINT" 2>&1)"; rc=$? +chk "the same NEW path with plain content does not warn" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" chk_no "no harness warn printed" "$out" "browser-harness-js skills/cdp/learnings" # The Seam rule. Same three states as Built, for the same reason one level up: a seam that was # never configured and a seam that was silently dropped read identically without the line, and # the seam is where an operator's whole distill half lives. out="$(printf 'no needs-you section at all\n\n**Built:** NOTHING: no candidates\n' | bash "$LINT" 2>&1)"; rc=$? -chk "a report with no Seam line fails" "$([ "$rc" -eq 1 ]; echo $?)" +chk "a report with no Seam line fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the finding names step -1" "$out" "step -1 (the before/after seams) owes an outcome" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's/^\*\*Seam:\*\* .*/**Seam:**/' | bash "$LINT" 2>&1)"; rc=$? -chk "an empty Seam line fails" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's/^\*\*Seam:\*\* .*/**Seam:**/' | bash "$LINT" 2>&1)"; rc=$? +chk "an empty Seam line fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the finding says it is empty" "$out" "is empty; name the side and skill that ran" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed 's|^\*\*Seam:\*\* .*|**Seam:** after learning-ledger ran: KEPT 2 of 7 queued|' | bash "$LINT" 2>&1)"; rc=$? -chk "a Seam line naming the side and skill passes" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed 's|^\*\*Seam:\*\* .*|**Seam:** after learning-ledger ran: KEPT 2 of 7 queued|' | bash "$LINT" 2>&1)"; rc=$? +chk "a Seam line naming the side and skill passes" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" rc=0; bash "$LINT" /nonexistent-report-file >/dev/null 2>&1 || rc=$? -chk "a missing file exits 2" "$([ "$rc" -eq 2 ]; echo $?)" +chk "a missing file exits 2" "$([ "$rc" -eq 2 ] && echo 0 || echo 1)" # The FYI rule. The block used to mix a skipped step, a state, an incident, and an ask under # one header, so an operator told to "follow the FYI" read nine ambiguous lines. Each bullet # now opens with SKIPPED, STATE, or INCIDENT, and an ask belongs in `Needs you` instead. -_fyi() { printf 'āœ… **Needs you:** NOTHING\n\n**FYI:**\n%s\n\n**Built:** NOTHING: no candidates\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- body\n' "$1"; } +_fyi() { printf 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)\n\n**FYI:**\n%s\n\n**Built:** NOTHING: no candidates\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- body\n' "$1"; } out="$(_fyi '- SKIPPED step 7b, its scan output went to the scratch file - STATE wrap.pull_past_dirty is false, the acme-app checkout stayed behind - INCIDENT the first merge raced CI, the retry landed it' | bash "$LINT" 2>&1)"; rc=$? -chk "an FYI block whose bullets are all tagged passes" "$([ "$rc" -eq 0 ]; echo $?)" +chk "an FYI block whose bullets are all tagged passes" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" out="$(_fyi '- the acme-app checkout stayed behind' | bash "$LINT" 2>&1)"; rc=$? -chk "an untagged FYI bullet fails" "$([ "$rc" -eq 1 ]; echo $?)" +chk "an untagged FYI bullet fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the finding names the three tags" "$out" "SKIPPED (a step that did not run), STATE" out="$(_fyi '- STATE wrap.pull_past_dirty is false, turning the knob on now works cleanly' | bash "$LINT" 2>&1)"; rc=$? -chk "a tagged FYI bullet carrying an ask fails" "$([ "$rc" -eq 1 ]; echo $?)" +chk "a tagged FYI bullet carrying an ask fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the finding sends the ask to Needs you" "$out" "that is an ask; move it to Needs you as DECIDE or RUN" out="$(_fyi '- NOTHING' | bash "$LINT" 2>&1)"; rc=$? -chk "the NOTHING sentinel needs no tag" "$([ "$rc" -eq 0 ]; echo $?)" +chk "the NOTHING sentinel needs no tag" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" -out="$(_report 'āœ… **Needs you:** NOTHING' | bash "$LINT" 2>&1)"; rc=$? -chk "a report with no FYI block still passes, the block is optional" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | bash "$LINT" 2>&1)"; rc=$? +chk "a report with no FYI block still passes, the block is optional" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" -out="$(printf 'āœ… **Needs you:** NOTHING\n\n**FYI:**\n\n**Built:** NOTHING: no candidates\n\n**Seam:** NOTHING: no seam configured\n' | bash "$LINT" 2>&1)"; rc=$? -chk "an FYI header with no bullets is not a finding" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(printf 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)\n\n**FYI:**\n\n**Built:** NOTHING: no candidates\n\n**Seam:** NOTHING: no seam configured\n' | bash "$LINT" 2>&1)"; rc=$? +chk "an FYI header with no bullets is not a finding" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" chk_has "commands/wrap.md names the three FYI tags" "$(cat "$KIT_DIR/commands/wrap.md")" "OPENS WITH ITS TAG" chk_has "commands/wrap.md says FYI carries no ask" "$(cat "$KIT_DIR/commands/wrap.md")" '**`FYI` carries no ask.**' @@ -323,99 +334,99 @@ chk_no "FYI is not described as never a task" "$(cat "$KIT_DIR/commands/wrap.md" # when a `REVIEW #` item in Needs you names its PR, because wrap never merges that PR. _follow() { printf '## Follow-through: t\n\n%s\n\n**What happened**\n- body\n\n**Built:**\n%s\n' "$1" "$2"; } FT_OK='- BUILT beta ENHANCE lib/wrap: wrap.sh (lane=normal, verified: bash tests/test-wrap.sh, #41)' -out="$(_follow 'āœ… **Needs you:** NOTHING' "$FT_OK" | bash "$LINT" 2>&1)"; rc=$? -chk "a follow-through report with no Seam line passes" "$([ "$rc" -eq 0 ]; echo $?)" -out="$(_follow 'āœ… **Needs you:** NOTHING' "$FT_OK" | sed 's/^## Follow-through: t/## Wrap: t/' | bash "$LINT" 2>&1)"; rc=$? -chk "the same body under a Wrap heading still owes a Seam line" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(_follow 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' "$FT_OK" | bash "$LINT" 2>&1)"; rc=$? +chk "a follow-through report with no Seam line passes" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" +out="$(_follow 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' "$FT_OK" | sed 's/^## Follow-through: t/## Wrap: t/' | bash "$LINT" 2>&1)"; rc=$? +chk "the same body under a Wrap heading still owes a Seam line" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the Wrap finding names step -1" "$out" "step -1 (the before/after seams) owes an outcome" -out="$(printf '## Follow-through: t\n\nāœ… **Needs you:** NOTHING\n\n**What happened**\n- body\n' | bash "$LINT" 2>&1)"; rc=$? -chk "a follow-through report still owes a Built line" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(printf '## Follow-through: t\n\nāœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)\n\n**What happened**\n- body\n' | bash "$LINT" 2>&1)"; rc=$? +chk "a follow-through report still owes a Built line" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" FT_FULL='- BUILT gamma NEW (precedent: nothing matched): lib/gamma (lane=full, verified: bash tests/test-gamma.sh, #71 DRAFT)' out="$(_follow 'šŸ”“ **Needs you:** a. REVIEW #71: full-lane design for gamma, the operator reviews the spec before it lands.' "$FT_FULL" | bash "$LINT" 2>&1)"; rc=$? -chk "a full-lane build paired with a REVIEW item for its PR passes" "$([ "$rc" -eq 0 ]; echo $?)" -out="$(_follow 'āœ… **Needs you:** NOTHING' "$FT_FULL" | bash "$LINT" 2>&1)"; rc=$? -chk "a full-lane build with no REVIEW item fails" "$([ "$rc" -eq 1 ]; echo $?)" +chk "a full-lane build paired with a REVIEW item for its PR passes" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" +out="$(_follow 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' "$FT_FULL" | bash "$LINT" 2>&1)"; rc=$? +chk "a full-lane build with no REVIEW item fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the finding says wrap never merges a full-lane PR" "$out" "wrap never merges a full-lane PR" out="$(_follow 'šŸ”“ **Needs you:** a. REVIEW #7: full-lane design for another candidate, blocked on your design call.' "$FT_FULL" | bash "$LINT" 2>&1)"; rc=$? -chk "a REVIEW item naming #7 does not cover PR #71" "$([ "$rc" -eq 1 ]; echo $?)" +chk "a REVIEW item naming #7 does not cover PR #71" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" out="$(_follow 'šŸ”“ **Needs you:** a. DECIDE #71: full-lane design for gamma, blocked on your design call.' "$FT_FULL" | bash "$LINT" 2>&1)"; rc=$? -chk "only a REVIEW item covers a full-lane build" "$([ "$rc" -eq 1 ]; echo $?)" +chk "only a REVIEW item covers a full-lane build" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" out="$(_report 'šŸ”“ **Needs you:** a. REVIEW #71: full-lane design for gamma, blocked on your design call.' | sed "s|^\*\*Built:\*\* .*|**Built:** ${FT_FULL#- }|" | bash "$LINT" 2>&1)"; rc=$? -chk "a full-lane build in a first Wrap report still fails, REVIEW or not" "$([ "$rc" -eq 1 ]; echo $?)" +chk "a full-lane build in a first Wrap report still fails, REVIEW or not" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the Wrap finding says a full lane is never built at session close" "$out" "a full lane is never built at session close" out="$(_follow 'šŸ”“ **Needs you:** a. REVIEW #71: full-lane design for gamma, blocked on your design call.' "${FT_FULL/ DRAFT/ OPEN}" | bash "$LINT" 2>&1)"; rc=$? -chk "a full-lane build not closed as a DRAFT fails, REVIEW or not" "$([ "$rc" -eq 1 ]; echo $?)" -out="$(_follow 'āœ… **Needs you:** NOTHING' "$FT_FULL" | sed 's/^- body$/- REVIEW #71: gamma waits for the operator/' | bash "$LINT" 2>&1)"; rc=$? -chk "a REVIEW line outside Needs you does not cover a full-lane build" "$([ "$rc" -eq 1 ]; echo $?)" +chk "a full-lane build not closed as a DRAFT fails, REVIEW or not" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" +out="$(_follow 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' "$FT_FULL" | sed 's/^- body$/- REVIEW #71: gamma waits for the operator/' | bash "$LINT" 2>&1)"; rc=$? +chk "a REVIEW line outside Needs you does not cover a full-lane build" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" out="$(_follow 'šŸ”“ **Needs you:** a. REVIEW #71: full-lane design for gamma. Say go and I merge it.' "$FT_FULL" | bash "$LINT" 2>&1)"; rc=$? -chk "a paired REVIEW item still fails the permission rule" "$([ "$rc" -eq 1 ]; echo $?)" +chk "a paired REVIEW item still fails the permission rule" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the permission finding fires on the REVIEW item" "$out" "asks permission instead of naming a blocker" -out="$(printf '[kit:wrap] follow-through: 1 builds, 0 follow-ups, 0 full-lane, 0 PR waits, running in background\n\n' | cat - <(_follow 'āœ… **Needs you:** NOTHING' "$FT_OK") | bash "$LINT" 2>&1)"; rc=$? -chk "a preamble line before the Follow-through heading still reads as a follow-through report" "$([ "$rc" -eq 0 ]; echo $?)" -out="$(_report 'āœ… **Needs you:** NOTHING' | sed '/^\*\*Seam:\*\*/d' | sed 's/^- body$/- the follow-through phase ran; see ## Follow-through: t below/' | bash "$LINT" 2>&1)"; rc=$? -chk "a Wrap report that mentions a follow-through heading later still owes a Seam line" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(printf '[kit:wrap] follow-through: 1 builds, 0 follow-ups, 0 full-lane, 0 PR waits, running in background\n\n' | cat - <(_follow 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' "$FT_OK") | bash "$LINT" 2>&1)"; rc=$? +chk "a preamble line before the Follow-through heading still reads as a follow-through report" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | sed '/^\*\*Seam:\*\*/d' | sed 's/^- body$/- the follow-through phase ran; see ## Follow-through: t below/' | bash "$LINT" 2>&1)"; rc=$? +chk "a Wrap report that mentions a follow-through heading later still owes a Seam line" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" out="$(_follow 'šŸ”“ **Needs you:** a. RUN the deploy. Want me to dispatch it?' "$FT_OK" | bash "$LINT" 2>&1)"; rc=$? -chk "a follow-through report keeps the permission rule" "$([ "$rc" -eq 1 ]; echo $?)" -out="$(_follow 'āœ… **Needs you:** NOTHING' "$FT_OK" | sed 's/^- body$/- body\n\n**FYI:**\n- the checkout stayed behind/' | bash "$LINT" 2>&1)"; rc=$? -chk "a follow-through report keeps the FYI tag rule" "$([ "$rc" -eq 1 ]; echo $?)" +chk "a follow-through report keeps the permission rule" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" +out="$(_follow 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' "$FT_OK" | sed 's/^- body$/- body\n\n**FYI:**\n- the checkout stayed behind/' | bash "$LINT" 2>&1)"; rc=$? +chk "a follow-through report keeps the FYI tag rule" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" FT_DECOY='- BUILT gamma NEW (precedent: nothing matched): lib/gamma (lane=full, verified: bash tests/test-gamma.sh after #99, #71 DRAFT)' out="$(_follow 'šŸ”“ **Needs you:** a. REVIEW #99: an earlier PR, blocked on your design call.' "$FT_DECOY" | bash "$LINT" 2>&1)"; rc=$? -chk "a decoy PR number in the verified text does not satisfy the pairing" "$([ "$rc" -eq 1 ]; echo $?)" +chk "a decoy PR number in the verified text does not satisfy the pairing" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" out="$(_follow 'šŸ”“ **Needs you:** a. REVIEW #71: gamma, blocked on your design call.' "$FT_DECOY" | bash "$LINT" 2>&1)"; rc=$? -chk "only the DRAFT number pairs" "$([ "$rc" -eq 0 ]; echo $?)" +chk "only the DRAFT number pairs" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" out="$(_follow 'šŸ”“ **Needs you:** a. REVIEW #12: another design, see #71 for context, blocked on your call.' "$FT_FULL" | bash "$LINT" 2>&1)"; rc=$? -chk "a second number later in a REVIEW item does not cover a PR" "$([ "$rc" -eq 1 ]; echo $?)" +chk "a second number later in a REVIEW item does not cover a PR" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" out="$(_follow 'šŸ”“ **Needs you:** a. REVIEWED #71: already looked at, blocked on nothing.' "$FT_FULL" | bash "$LINT" 2>&1)"; rc=$? -chk "REVIEWED is not REVIEW" "$([ "$rc" -eq 1 ]; echo $?)" +chk "REVIEWED is not REVIEW" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" out="$(_follow 'šŸ”“ **Needs you:** a. REVIEW #71: gamma, blocked on your design call.' "$FT_FULL - BUILT delta NEW (precedent: nothing matched): lib/delta (lane=full, verified: bash tests/test-delta.sh, #72 DRAFT)" | bash "$LINT" 2>&1)"; rc=$? -chk "two full-lane builds, one unpaired, fail" "$([ "$rc" -eq 1 ]; echo $?)" +chk "two full-lane builds, one unpaired, fail" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the finding names the unpaired item" "$out" "item 2 is a full-lane build" -chk "exactly one finding for the unpaired item" "$([ "$(printf '%s\n' "$out" | grep -c 'is a full-lane build')" -eq 1 ]; echo $?)" +chk "exactly one finding for the unpaired item" "$([ "$(printf '%s\n' "$out" | grep -c 'is a full-lane build')" -eq 1 ] && echo 0 || echo 1)" out="$(_fyi '- STATE wrap.follow_through is off, 3 in-lane items stay REPORTED; /kit:wrap follow builds them' | bash "$LINT" 2>&1)"; rc=$? -chk "the off-mode FYI row passes the ask rule" "$([ "$rc" -eq 0 ]; echo $?)" +chk "the off-mode FYI row passes the ask rule" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" # ------------------------------------------------------------- STE-lite prose # commands/wrap.md step 9 "Prose is STE-lite": no semicolon, no sentence over 20 words, # counted outside backtick spans, in Needs you, What happened, the FYI Fact cell, and the # Left alone Why cell. A contraction only warns. -_ste() { printf '## Wrap: t\n\nāœ… **Needs you:** NOTHING\n\n**Left alone:**\n| Repo | Item | Owner | Why |\n|---|---|---|---|\n| r | wt | this pass | %s |\n\n**Built:** NOTHING: no candidates\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- %s\n\n**FYI:**\n| Tag | Fact | Home |\n|---|---|---|\n| STATE | %s | |\n' "${2:-kept for review}" "$1" "${3:-the knob is false}"; } +_ste() { printf '## Wrap: t\n\nāœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)\n\n**Left alone:**\n| Repo | Item | Owner | Why |\n|---|---|---|---|\n| r | wt | this pass | %s |\n\n**Built:** NOTHING: no candidates\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- %s\n\n**FYI:**\n| Tag | Fact | Home |\n|---|---|---|\n| STATE | %s | |\n' "${2:-kept for review}" "$1" "${3:-the knob is false}"; } W20="one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty" out="$(_ste "Fixed the lint. It now fails a long sentence. Version v1.2.3 shipped in abc1234." | bash "$LINT" 2>&1)"; rc=$? -chk "an STE report passes" "$([ "$rc" -eq 0 ]; echo $?)" +chk "an STE report passes" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" out="$(_ste "$W20" | bash "$LINT" 2>&1)"; rc=$? -chk "a 20-word sentence passes" "$([ "$rc" -eq 0 ]; echo $?)" +chk "a 20-word sentence passes" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" out="$(_ste "Fixed the bug; it now passes." | bash "$LINT" 2>&1)"; rc=$? -chk "a semicolon in What happened fails" "$([ "$rc" -eq 1 ]; echo $?)" +chk "a semicolon in What happened fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the semicolon finding names the line" "$out" "line 15: semicolon in prose" out="$(_ste "$W20 twentyone" | bash "$LINT" 2>&1)"; rc=$? -chk "a 21-word sentence fails" "$([ "$rc" -eq 1 ]; echo $?)" +chk "a 21-word sentence fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the long-sentence finding names the count" "$out" "sentence of 21 words" out="$(_ste 'Ran `a; b` and `one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen` clean.' | bash "$LINT" 2>&1)"; rc=$? -chk "a semicolon and long text inside backticks pass" "$([ "$rc" -eq 0 ]; echo $?)" +chk "a semicolon and long text inside backticks pass" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" out="$(_ste "Fixed. $W20. Done." | bash "$LINT" 2>&1)"; rc=$? -chk "sentences are split on a period and a space" "$([ "$rc" -eq 0 ]; echo $?)" +chk "sentences are split on a period and a space" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" out="$(_ste "ok" "kept; for review" | bash "$LINT" 2>&1)"; rc=$? -chk "a semicolon in a Left alone Why cell fails" "$([ "$rc" -eq 1 ]; echo $?)" +chk "a semicolon in a Left alone Why cell fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" out="$(_ste "ok" "ok" "$W20 twentyone" | bash "$LINT" 2>&1)"; rc=$? -chk "a 21-word FYI Fact cell fails" "$([ "$rc" -eq 1 ]; echo $?)" +chk "a 21-word FYI Fact cell fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" out="$(printf '## Wrap: t\n\nšŸ”“ **Needs you:**\na. RUN the deploy; it needs your 2FA.\n\n**Built:** NOTHING: no candidates\n\n**Seam:** NOTHING: no seam configured\n' | bash "$LINT" 2>&1)"; rc=$? -chk "a semicolon in a Needs you item fails" "$([ "$rc" -eq 1 ]; echo $?)" +chk "a semicolon in a Needs you item fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" out="$(_ste "It doesn't break." | bash "$LINT" 2>&1)"; rc=$? -chk "a contraction warns and still passes" "$([ "$rc" -eq 0 ]; echo $?)" +chk "a contraction warns and still passes" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" chk_has "the contraction warning names the line" "$out" "warn line 15: contraction" @@ -425,26 +436,26 @@ chk_has "the contraction warning names the line" "$out" "warn line 15: contracti # pinned to a scratch dir per case, so the real machine's [decide] block never reaches the others. FLICK_ON="$TMPD/flick-on"; mkdir -p "$FLICK_ON"; printf '[decide]\npoints = "wrap-7b"\n' > "$FLICK_ON/kit.toml" FLICK_OFF="$TMPD/flick-off"; mkdir -p "$FLICK_OFF"; printf '[decide]\npoints = ""\n' > "$FLICK_OFF/kit.toml" -_fyi_row() { printf '%s\n\n**FYI:**\n| Tag | Fact | Home |\n|---|---|---|\n| STATE | %s | |\n' "$(_report 'āœ… **Needs you:** NOTHING')" "$1"; } +_fyi_row() { printf '%s\n\n**FYI:**\n| Tag | Fact | Home |\n|---|---|---|\n| STATE | %s | |\n' "$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)')" "$1"; } -out="$(_report 'āœ… **Needs you:** NOTHING' | KIT_CONFIG_OPERATOR="$FLICK_ON" bash "$LINT" 2>&1)"; rc=$? -chk "flick on, no flick row: the lint fails" "$([ "$rc" -eq 1 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | KIT_CONFIG_OPERATOR="$FLICK_ON" bash "$LINT" 2>&1)"; rc=$? +chk "flick on, no flick row: the lint fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" chk_has "the finding names the flick row" "$out" "no 'flick wrap-7b:' row" out="$(_fyi_row 'flick wrap-7b: 2 answered, 0 denied, 0 error (jev)' | KIT_CONFIG_OPERATOR="$FLICK_ON" bash "$LINT" 2>&1)"; rc=$? -chk "flick on, a flick row: clean" "$([ "$rc" -eq 0 ]; echo $?)" +chk "flick on, a flick row: clean" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" out="$(_fyi_row 'flick wrap-7b: no pairs (jev)' | KIT_CONFIG_OPERATOR="$FLICK_ON" bash "$LINT" 2>&1)"; rc=$? -chk "flick on, the no-pairs row: clean" "$([ "$rc" -eq 0 ]; echo $?)" +chk "flick on, the no-pairs row: clean" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" -out="$(_report 'āœ… **Needs you:** NOTHING' | KIT_CONFIG_OPERATOR="$FLICK_OFF" bash "$LINT" 2>&1)"; rc=$? -chk "flick off, no flick row: clean" "$([ "$rc" -eq 0 ]; echo $?)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | KIT_CONFIG_OPERATOR="$FLICK_OFF" bash "$LINT" 2>&1)"; rc=$? +chk "flick off, no flick row: clean" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" out="$(printf 'x\n\n**Built:** SKIPPED: distill is off\n\n**Seam:** NOTHING: no seam configured\n' | KIT_CONFIG_OPERATOR="$FLICK_ON" bash "$LINT" 2>&1)"; rc=$? -chk "flick on, step 7b skipped with a reason: no flick row owed" "$([ "$rc" -eq 0 ]; echo $?)" +chk "flick on, step 7b skipped with a reason: no flick row owed" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" out="$(printf '## Follow-through: t\n\n**Built:** NOTHING: no candidates\n' | KIT_CONFIG_OPERATOR="$FLICK_ON" bash "$LINT" 2>&1)"; rc=$? -chk "flick on, a follow-through report owes no flick row" "$([ "$rc" -eq 0 ]; echo $?)" +chk "flick on, a follow-through report owes no flick row" "$([ "$rc" -eq 0 ] && echo 0 || echo 1)" From 16bcaf5b2b59fc4d13d8c98c9e50130c94f564ba Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 13:11:02 +0700 Subject: [PATCH 15/19] docs(verification): record the review fixes and their negative controls --- docs/verification/wrap-cut-call.md | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/docs/verification/wrap-cut-call.md b/docs/verification/wrap-cut-call.md index dec2411d..4c8e780c 100644 --- a/docs/verification/wrap-cut-call.md +++ b/docs/verification/wrap-cut-call.md @@ -119,6 +119,41 @@ Stops and writes: every `rate_limit_event` `allowed`, seven-day 0.46 to 0.48. A Against the merged OLD totals (judged before this work), round 4 NEW also holds 5 of 6 with no 2-point row drop. Judge noise is large: the same OLD report scored 11, 9 and 7 for P2 across rounds. The command was tuned over four rounds on these six sessions. Commit `6c9a0cfc` (self-wrap and read-only-repo wording) came after the scored round and is not re-scored. +## Review fixes (after `37b3ac23`) + +A fresh read-only review found one HIGH and five MEDIUM defects. Each fix has a test that fails on `37b3ac23`. None of these fixes was re-scored on the replay. + +| Finding | Fix | Red on `37b3ac23` | +|---|---|---| +| HIGH: the `cd` / `git -C` scan indexed a string, so no such target was gathered | take each capture's first group | `a git -C target with no other mention is a gathered repo`, `a cd target ...` | +| A truncated transcript line stopped the read silently | parse line by line; count `skipped_lines` | `a truncated line is counted, not silent`, plus the repo and the acted PR after it | +| A bare `NOTHING` passed with no walk named | `## Wrap:` reports need `NOTHING (walked: ...)`; the lint refuses a bare or count-free one | `a bare NOTHING in a wrap report fails the lint`, `a walk with no count fails the lint` | +| A URL-less `gh pr merge` got no live read | resolve by number against its cwd's origin, or by its record's branch | `a bare-number merge resolves ...`, `a branch-only merge resolves ...`, `both URL-less merges are read live ...` | +| `--mark-dir` could sit in a gathered repo or `$HOME` | refuse `$HOME` and any path inside a git work tree | `a --mark-dir inside a gathered repo is refused`, `... equal to $HOME is refused` | +| An empty `--mark-dir` skipped step 0 silently | refuse it with exit 64 | `an empty --mark-dir is refused, so step 0 never silently skips` | + +```text +Command: git show 37b3ac23:lib/wrap/wrap-session.sh > lib/wrap/wrap-session.sh; git show 37b3ac23:lib/wrap/report-lint.sh > lib/wrap/report-lint.sh; bash tests/test-wrap-session.sh; bash tests/test-wrap-report-lint.sh (in a git archive copy of HEAD) +Exit: 1 +Output: +test-wrap-session: 133 passed, 16 FAILED of 149 +test-wrap-report-lint: 161 passed, 3 FAILED of 164 +Verdict: RED, as expected +``` + +```text +Command: bash tests/test-wrap-session.sh; bash tests/test-wrap-report-lint.sh; bash tests/test-harvest-sweep.sh; bash tests/test-shared-lookups.sh +Exit: 0 +Output: +test-wrap-session: all 149 passed +test-wrap-report-lint: all 164 passed +All harvest sweep tests passed. +test-shared-lookups: all 15 passed +Verdict: PASS +``` + +The LOW findings (7 to 12) are not fixed here. + ## Not proven locally - The full suite (`bash tests/run-all.sh`) did not run locally: the host was loaded. CI's `--changed` run passed. From 796ac4295ce5b1eb8ba454a6a8a0292c374231be Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 13:28:24 +0700 Subject: [PATCH 16/19] fix(wrap): resolve relative cd and git -C targets against the record's cwd A relative target (`cd sub && gh pr merge 5`) was tested against the wrap process's own cwd, so a merge could be credited to an unrelated repo while the session's PR was missed. Relative cd, git -C and file-path targets are now joined onto the transcript record's cwd, only a cd before the gh pr call counts, and a merge whose directory lands in no git repo with a GitHub origin is listed in transcript.unresolved_merges, never credited. ## How I verified it bash tests/test-wrap-session.sh -> test-wrap-session: all 152 passed on 16bcaf5b's wrap-session.sh -> 148 passed, 4 FAILED of 152 --- docs/verification/wrap-cut-call.md | 24 ++++++++++++++++++ lib/wrap/wrap-session.sh | 39 +++++++++++++++++++----------- tests/test-wrap-session.sh | 18 +++++++++++++- 3 files changed, 66 insertions(+), 15 deletions(-) diff --git a/docs/verification/wrap-cut-call.md b/docs/verification/wrap-cut-call.md index 4c8e780c..0ba927f6 100644 --- a/docs/verification/wrap-cut-call.md +++ b/docs/verification/wrap-cut-call.md @@ -154,6 +154,30 @@ Verdict: PASS The LOW findings (7 to 12) are not fixed here. +### Re-review fix (after `16bcaf5b`) + +A relative `cd` or `git -C` target (`cd sub && gh pr merge 5`) resolved against the wrap's own working directory. It could credit an unrelated repo's PR and miss the session's own PR. Targets are now joined onto the transcript record's cwd, and only a `cd` before the `gh pr` call counts. A merge whose directory lands in no git repo with a GitHub origin goes to `transcript.unresolved_merges` and the summary; it is never credited. + +```text +Command: git show 16bcaf5b:lib/wrap/wrap-session.sh > lib/wrap/wrap-session.sh; bash tests/test-wrap-session.sh (in a git archive copy of HEAD) +Exit: 1 +Output: + FAIL the summary names the transcript facts + FAIL a relative cd merge credits the record's repo + FAIL a relative cd merge never credits the wrap's own repo + FAIL a merge whose cd lands in no repo is reported unresolved, not credited +test-wrap-session: 148 passed, 4 FAILED of 152 +Verdict: RED, as expected +``` + +```text +Command: bash tests/test-wrap-session.sh +Exit: 0 +Output: +test-wrap-session: all 152 passed +Verdict: PASS +``` + ## Not proven locally - The full suite (`bash tests/run-all.sh`) did not run locally: the host was loaded. CI's `--changed` run passed. diff --git a/lib/wrap/wrap-session.sh b/lib/wrap/wrap-session.sh index c0fc5d8e..9b342d56 100644 --- a/lib/wrap/wrap-session.sh +++ b/lib/wrap/wrap-session.sh @@ -588,6 +588,7 @@ _session_transcript_json() { # `cd` target, else the record's cwd), and one with no number against that record's git branch. # Every other URL was only mentioned, and a report never credits the session with it. raw="$(jq -rn ' + def abs($cwd): gsub("^[\"'"'"']|[\"'"'"']$"; "") | if startswith("/") or startswith("~/") then . elif . == "-" or . == "" or $cwd == "" then "" else $cwd + "/" + . end; [inputs | select(.__bad != true) | . as $r | .message.content[]? | select(type == "object") | . + {_cwd:($r.cwd // ""), _branch:($r.gitBranch // "")}] as $b | [$b[] | select(.type == "tool_use" and .name == "Bash") @@ -599,23 +600,30 @@ _session_transcript_json() { | select($c | test("https://github\\.com/[^ ]+/pull/[0-9]+") | not) | ([$c | scan("(?:--repo|-R)[ =]+([A-Za-z0-9][A-Za-z0-9-]*/[A-Za-z0-9_.-]+)") | .[0]] | first // "") as $repo | ([$c | scan("gh +pr +(?:merge|ready|close) +([0-9]+)") | .[0]] | first // "") as $n - | ([$c | scan("\\bcd\\s+(\"[^\"]+\"|'"'"'[^'"'"']+'"'"'|[^\\s;&|)]+)") | .[0]] | last // $cwd) as $dir + | ([$c | sub("gh +pr +(?:merge|ready|close)[\\s\\S]*$"; "") | scan("\\bcd\\s+(\"[^\"]+\"|'"'"'[^'"'"']+'"'"'|[^\\s;&|)]+)") | .[0]] | if length == 0 then $cwd else (last | abs($cwd)) end) as $dir | if $repo != "" and $n != "" then "https://github.com/\($repo)/pull/\($n)" else "\u0001BARE\u001f\($dir)\u001f\($repo)\u001f\($n)\u001f\($br)" end) ' "$clean" 2>/dev/null)" bare="$(printf '%s\n' "$raw" | grep -a "$(printf '^\001BARE')" | cut -c2-)" + unknown="$(mktemp "${TMPDIR:-/tmp}/kit.XXXXXX")" acted="$( { printf '%s\n' "$raw" | grep -av "$(printf '^\001BARE')" # \037 (unit separator), not a tab: IFS would fold a run of tabs and shift empty fields. + # A relative `cd` target is already joined onto its record's cwd; a target that does not + # land in a git repo with a GitHub origin is UNKNOWN, never credited to another repo. while IFS="$(printf '\037')" read -r _ dir slug n branch; do - [ -n "$dir$slug" ] || continue + [ -n "$dir$slug$n$branch" ] || continue if [ -z "$slug" ]; then - d="$(printf '%s' "$dir" | tr -d "\"'" | sed "s#^~/#$HOME/#")" + d="$(printf '%s' "$dir" | sed "s#^~/#$HOME/#")" + case "$d" in /*) ;; *) d="" ;; esac while [ -n "$d" ] && [ "$d" != "/" ] && [ ! -d "$d" ]; do d="$(dirname "$d")"; done - [ -d "$d" ] && [ "$d" != "/" ] || continue - main="$(_session_main_checkout "$d" 2>/dev/null)" || continue - slug="$(_session_repo_slug "$(git -C "$main" remote get-url origin 2>/dev/null)" 2>/dev/null)" + main="" + [ -n "$d" ] && [ "$d" != "/" ] && main="$(_session_main_checkout "$d" 2>/dev/null)" + [ -n "$main" ] && slug="$(_session_repo_slug "$(git -C "$main" remote get-url origin 2>/dev/null)" 2>/dev/null)" + fi + if [ -z "$slug" ]; then + printf 'gh pr merge %s in %s\n' "${n:-branch ${branch:-?}}" "${dir:-an unknown directory}" >> "$unknown" + continue fi - [ -n "$slug" ] || continue if [ -z "$n" ] && [ -n "$branch" ] && [ "$(_gh_state)" = ok ]; then n="$(gh pr list --repo "$slug" --head "$branch" --state all --limit 1 --json number --jq '.[0].number // empty' 2>/dev/null)" # merged-ok: names the PR a branch-only merge acted on, read live after; never a deletion proof fi @@ -629,13 +637,15 @@ EOF_SESSION_BARE [ -n "$acted" ] || acted='[]' prs="$(jq -cn --argjson a "$acted" --argjson p "$prs" '$a + [$p[] | select(. as $x | $a | index($x) | not)]')" paths="$(jq -r ' - select(.__bad != true) | - (select(.cwd != null) | .cwd), + def abs($cwd): gsub("^[\"'"'"']|[\"'"'"']$"; "") | if startswith("/") or startswith("~/") then . elif . == "-" or . == "" or $cwd == "" then "" else $cwd + "/" + . end; + select(.__bad != true) | (.cwd // "") as $cwd | + (select($cwd != "") | $cwd), (.message.content[]? | select(type == "object" and .type == "tool_use") | .input - | ((.file_path // .notebook_path // empty), - ((.command // "") | [scan("(?:git\\s+-C|\\bcd)\\s+(\"[^\"]+\"|'"'"'[^'"'"']+'"'"'|[^\\s;&|)]+)") | .[0]] | .[]))) + | ((.file_path // .notebook_path // empty | abs($cwd)), + ((.command // "") | [scan("(?:git\\s+-C|\\bcd)\\s+(\"[^\"]+\"|'"'"'[^'"'"']+'"'"'|[^\\s;&|)]+)") | .[0] | abs($cwd)] | .[]))) ' "$clean" 2>/dev/null | tr -d "\"'" | sed "s#^~/#$HOME/#" | grep '^/' | awk '!seen[$0]++')" - rm -f "$clean" "$lead_clean" + unresolved="$(_session_lines_json < "$unknown")"; [ -n "$unresolved" ] || unresolved='[]' + rm -f "$clean" "$lead_clean" "$unknown" repos_json="$(while IFS= read -r p; do [ -n "$p" ] || continue d="$p" @@ -651,7 +661,8 @@ EOF_SESSION_TPATHS [ -n "$repos_json" ] || repos_json='[]' jq -cn --arg path "$t" --argjson start "$start" --argjson prs "$prs" --argjson repos "$repos_json" \ --argjson subagents "$(( ${#tfiles[@]} - 1 ))" --argjson acted "$acted" --argjson skipped "$skipped" \ - '{path:$path,started_at_epoch:$start,subagent_transcripts:$subagents,skipped_lines:$skipped,prs:$prs,acted_prs:$acted,repos:$repos}' + --argjson unresolved "$unresolved" \ + '{path:$path,started_at_epoch:$start,subagent_transcripts:$subagents,skipped_lines:$skipped,prs:$prs,acted_prs:$acted,unresolved_merges:$unresolved,repos:$repos}' } # _session_pr_refs ... -- every PR ref as `owner/name#n`, one per line, deduplicated. @@ -728,7 +739,7 @@ _session_summary_text() { "wrap-session/1 generated_at=\(.generated_at) epoch=\(.generated_at_epoch) repos=\(.summary.repos) open_own_prs=\(.summary.open_own_prs) pending_prs=\(.summary.pending_prs) named_prs=\(.summary.named_prs) foreign_activity_repos=\(.summary.foreign_activity_repos)", "config " + (.config | to_entries | map("\(.key)=\(.value | v)") | join(" ")), (.transcript // null | select(. != null) | - "transcript started_at_epoch=\(.started_at_epoch | v) subagent_transcripts=\(.subagent_transcripts) skipped_lines=\(.skipped_lines) repos=\(.repos | join(",") | if . == "" then "-" else . end) prs=\(.prs | length) acted_prs=\(.acted_prs | join(",") | if . == "" then "-" else . end)"), + "transcript started_at_epoch=\(.started_at_epoch | v) subagent_transcripts=\(.subagent_transcripts) skipped_lines=\(.skipped_lines) repos=\(.repos | join(",") | if . == "" then "-" else . end) prs=\(.prs | length) unresolved_merges=\(.unresolved_merges | length) acted_prs=\(.acted_prs | join(",") | if . == "" then "-" else . end)"), "writer_since=\(.since | v)", "activity_log configured=\(.activity_log.configured) target=\(.activity_log.resolved | v) writable=\(.activity_log.writable) error=\(.activity_log.error | v)", (.named_prs // null | select(. != null) | diff --git a/tests/test-wrap-session.sh b/tests/test-wrap-session.sh index 2e1a4d38..fc6db55f 100755 --- a/tests/test-wrap-session.sh +++ b/tests/test-wrap-session.sh @@ -405,7 +405,7 @@ chk "transcript PRs and --prs still cost one GraphQL call" "$([ "$(wc -l < "$GQL out="$(GQL_STUB_JSON="$gql_doc" gather --json --transcript "$tfile" --prs acme/ops#7 --since 1700000000 "$clone" 2>/dev/null)" jqok "an explicit --since wins and a named repo is not gathered twice" "$out" '.since == 1700000000 and (.repos | length) == 1 and ([.named_prs.rows[].ref] | index("acme/ops#7")) != null' sum="$(GQL_STUB_JSON="$gql_doc" gather --summary --transcript "$tfile" 2>/dev/null)" -chk_has "the summary names the transcript facts" "$sum" "transcript started_at_epoch=$want_epoch subagent_transcripts=1 skipped_lines=0 repos=$clone_p prs=3 acted_prs=acme/ops#6190,acme/ops#7" +chk_has "the summary names the transcript facts" "$sum" "transcript started_at_epoch=$want_epoch subagent_transcripts=1 skipped_lines=0 repos=$clone_p prs=3 unresolved_merges=0 acted_prs=acme/ops#6190,acme/ops#7" # A repo named only by transcript text runs no repo-configured program. The control run (the # same repo named on the command line, no --transcript) proves the planted hook does fire. printf '#!/bin/sh\ntouch "%s/fsmonitor-ran"\nexit 1\n' "$TMPD" > "$TMPD/fsmon.sh"; chmod +x "$TMPD/fsmon.sh" @@ -457,6 +457,22 @@ jqok "a branch-only merge resolves through its branch" "$out" '.transcript.acted jqok "both URL-less merges are read live, never taken from the transcript" "$out" '([.named_prs.rows[] | select(.ref == "acme/merged#42") | .state][0]) == "MERGED" and ([.named_prs.rows[] | select(.ref == "acme/merged#43") | .state][0]) == "OPEN"' chk_has "the branch lookup asks for that head" "$(cat "$GQL_STUB_CALLS")" "--head feat/x" +# A relative `cd` resolves against the record's cwd, never the wrap's own cwd: run the gather +# from an unrelated repo whose origin would otherwise take the credit. A `cd` after the merge +# does not move it. +make_clone tx5 rmain main main; make_clone tx6 rmain main main +tx5_p="$(cd "$TMPD/clone-tx5" && pwd -P)"; tx6_p="$(cd "$TMPD/clone-tx6" && pwd -P)" +git -C "$TMPD/clone-tx5" remote set-url origin https://github.com/acme/session-repo.git +git -C "$TMPD/clone-tx6" remote set-url origin https://github.com/acme/unrelated.git +mkdir -p "$tx5_p/sub" "$tx6_p/sub" "$TMPD/plain-dir" +tr5="$TMPD/projects/sess5.jsonl" +jq -cn --arg cwd "$tx5_p" '{type:"assistant",timestamp:"2026-11-27T04:00:00Z",cwd:$cwd,message:{content:[{type:"tool_use",id:"r1",name:"Bash",input:{command:"cd sub && gh pr merge 5 --squash; cd /tmp"}}]}}' > "$tr5" +jq -cn --arg cwd "$TMPD/plain-dir" '{type:"assistant",timestamp:"2026-11-27T04:01:00Z",cwd:$cwd,message:{content:[{type:"tool_use",id:"r2",name:"Bash",input:{command:"cd nowhere && gh pr merge 6 --squash"}}]}}' >> "$tr5" +out="$(cd "$tx6_p" && GQL_STUB_JSON='{"data":{}}' gather --json --transcript "$tr5" 2>/dev/null)" +jqok "a relative cd merge credits the record's repo" "$out" '.transcript.acted_prs | index("acme/session-repo#5") != null' +jqok "a relative cd merge never credits the wrap's own repo" "$out" '[.transcript.acted_prs[] | select(startswith("acme/unrelated"))] == []' +jqok "a merge whose cd lands in no repo is reported unresolved, not credited" "$out" '(.transcript.unresolved_merges | length) == 1 and (.transcript.unresolved_merges[0] | test("gh pr merge 6 in .*plain-dir/nowhere"))' + # =========================================================================== echo "=== --mark-dir: never empty, never \$HOME, never inside a work tree ===" # =========================================================================== From a3a02f0464c306771a0e1669344a8ceccff5e15b Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 13:48:10 +0700 Subject: [PATCH 17/19] feat(wrap): a one-screen report whose specifics come from live reads A holdout found wrap reports long and dense, with wrong counts, PR purposes and actors. This fixes both by category; no holdout or replay session was read or re-run. - commands/wrap.md: a one-line **Result:** card first, a 40 non-blank-line budget, one fact per bullet, no fact told twice. Every count, PR number, PR purpose and actor comes from the gather or a verbatim digest line; the miner's claims are leads to check, and an unchecked detail stays out. - report-lint.sh: a `## Wrap:` report over 40 non-blank lines fails. - wrap session: named PRs carry mergedBy; recent merged PRs carry author and mergedBy; the summary prints author= and merged_by= for both. ## How I verified it bash tests/test-wrap-session.sh -> test-wrap-session: all 158 passed bash tests/test-wrap-report-lint.sh -> test-wrap-report-lint: all 168 passed on 796ac429's scripts -> 5 and 2 of the new cases fail --- commands/wrap.md | 9 +++++++-- docs/verification/wrap-cut-call.md | 31 ++++++++++++++++++++++++++++++ lib/wrap/report-lint.sh | 13 +++++++++++-- lib/wrap/wrap-session.sh | 12 ++++++------ tests/test-wrap-report-lint.sh | 11 +++++++++++ tests/test-wrap-session.sh | 11 +++++++++-- 6 files changed, 75 insertions(+), 12 deletions(-) diff --git a/commands/wrap.md b/commands/wrap.md index a9f7abb9..fdfd9371 100644 --- a/commands/wrap.md +++ b/commands/wrap.md @@ -82,18 +82,22 @@ When any write step ran, run one final read-only gather over the same repos befo **Needs-you check, before writing `NOTHING`.** Walk the digest's replies and the miner's open owner actions, newest first; a self-wrap has neither, so it walks its own replies and asks this session. List every owner action they name: an ask to the operator, a blocker, a lettered `a.` `b.` item, "needs Han" or "needs you", an approval, and a merge, close, or click left to the owner. An action a later reply, the miner, or a gather row shows done is closed; leave it out. A choice the session or a worker made itself is not an owner action. Every other one goes under `Needs you`. When the newest mention leaves it open but you cannot prove it still is, list it with `check`: `a. RUN check . .` Write `NOTHING` only when this walk found no open item, never because the gather shows nothing, and name the walk: `NOTHING (walked: digest replies, miner actions)` (a self-wrap: `NOTHING (walked: own replies )`). The lint refuses an unwalked `NOTHING`. +**Where each detail comes from.** Every count, PR number, PR purpose, and actor in the report comes from the gather (a live PR row: `title`, `author`, `merged_by`, state) or a verbatim line of the recall digest. The miner's claims are leads: check each against the gather or the digest before it enters the report. A detail you cannot check stays out; never guess it. A PR's purpose is its live title, not a summary of the transcript. An actor is the gather's `author` or `merged_by`, or the digest line that names who acted: the operator, the session, a bot, or a worker are different actors. + Draft the skim-first report, write it to scratch. Run the lint before printing: `bash lib/wrap/report-lint.sh `. Fix or do what the lint names, then re-run. Never read the lint's source; when it cannot run, say so in one `SKIPPED` FYI row. The shape is: ```markdown ## Wrap: +**Result:** + āœ… **Needs you:** NOTHING (walked: digest replies, miner actions) -- or -- šŸ”“ **Needs you:** a. DECIDE | RUN | REVIEW | UNBLOCK . . . **What happened** -- ****: . . . . +- ****: . **Shipped** | Repo | PR | Merge | Deploy | @@ -119,7 +123,8 @@ a. DECIDE | RUN | REVIEW | UNBLOCK . . &2 + findings=$((findings + 1)) +fi +# Walk the report. `in_block` is on between the `Needs you` header and the next bold section +# header, so only that section is judged; a `What happened` sentence may say anything. lineno=0 in_block=0 while IFS= read -r line; do diff --git a/lib/wrap/wrap-session.sh b/lib/wrap/wrap-session.sh index 9b342d56..a38c9048 100644 --- a/lib/wrap/wrap-session.sh +++ b/lib/wrap/wrap-session.sh @@ -420,11 +420,11 @@ EOF_SESSION_PRS me="$(gh api user --jq .login 2>/dev/null)" merged_raw="$(gh pr list --repo "$url" --state merged --limit 20 \ - --json number,title,headRefName,mergedAt,mergeCommit,author 2>/dev/null)" # merged-ok: recent merged PRs are deploy-report facts, never a deletion proof + --json number,title,headRefName,mergedAt,mergeCommit,author,mergedBy 2>/dev/null)" # merged-ok: recent merged PRs are deploy-report facts, never a deletion proof if [ -n "$merged_raw" ] && [ -n "$me" ]; then merged="$(printf '%s' "$merged_raw" | jq -c --arg me "$me" \ '[.[] | select((.author.login // "") | ascii_downcase == ($me | ascii_downcase))] - | .[0:5] | map({number,title,headRefName,mergedAt,merge_sha:(.mergeCommit.oid // null)})' 2>/dev/null)" # merged-ok: recent merged PR fields are deploy-report facts, never a deletion proof + | .[0:5] | map({number,title,headRefName,mergedAt,merge_sha:(.mergeCommit.oid // null),author:(.author.login // null),merged_by:(.mergedBy.login // null)})' 2>/dev/null)" # merged-ok: recent merged PR fields are deploy-report facts, never a deletion proof fi [ -n "$merged" ] || merged='[]' merged="$(printf '%s' "$merged" | jq -c --arg slug "$slug" \ @@ -705,7 +705,7 @@ _session_named_prs_json() { END { printf "query {" for (i = 0; i < n; i++) { split(order[i], on, "/"); printf " r%d: repository(owner: \"%s\", name: \"%s\") {%s }", i, on[1], on[2], prs[i] } - printf " } fragment F on PullRequest { number title url state merged mergedAt mergeCommit { oid statusCheckRollup { state } } headRefName baseRefName isDraft author { login } }\n" # merged-ok: a live PR merge state read as a report fact, never a deletion proof + printf " } fragment F on PullRequest { number title url state merged mergedAt mergeCommit { oid statusCheckRollup { state } } headRefName baseRefName isDraft author { login } mergedBy { login } }\n" # merged-ok: a live PR merge state read as a report fact, never a deletion proof }')" # gh exits non-zero on a partial GraphQL error but still prints the data, so stdout is read either way. out="$(gh api graphql -f query="$query" 2>/dev/null)" @@ -724,7 +724,7 @@ _session_named_prs_json() { {ref:$ref, number:$pr.number, title:$pr.title, url:$pr.url, state:$pr.state, merged:$pr.merged, merged_at:$pr.mergedAt, merge_sha:($pr.mergeCommit.oid // null), # merged-ok: a live PR merge state read as a report fact, never a deletion proof merge_checks:($pr.mergeCommit.statusCheckRollup.state // null), head_branch:$pr.headRefName, - base_branch:$pr.baseRefName, draft:$pr.isDraft, author:($pr.author.login // null), error:null} + base_branch:$pr.baseRefName, draft:$pr.isDraft, author:($pr.author.login // null), merged_by:($pr.mergedBy.login // null), error:null} end' | jq -s .)" [ -n "$rows" ] || rows='[]' jq -cn --arg now "$now" --argjson rows "$rows" '{gh_state:"ok",read_at:$now,error:null,rows:$rows}' @@ -745,7 +745,7 @@ _session_summary_text() { (.named_prs // null | select(. != null) | "named_prs read_at=\(.read_at) gh=\(.gh_state) error=\(.error | v)", (.rows[] | if .error then " pr \(.ref) ERROR \(.error)" - else " pr \(.ref)\(if .session then " session=\(.session)" else "" end) state=\(.state) merged=\(.merged) merged_at=\(.merged_at | v) merge=\(.merge_sha | sha) merge_checks=\(.merge_checks | v) head=\(.head_branch | v) draft=\(.draft) author=\(.author | v) \"\(.title)\"" end)), # merged-ok: a live PR merge state printed as a report fact, never a deletion proof + else " pr \(.ref)\(if .session then " session=\(.session)" else "" end) state=\(.state) merged=\(.merged) merged_at=\(.merged_at | v) merge=\(.merge_sha | sha) merge_checks=\(.merge_checks | v) head=\(.head_branch | v) draft=\(.draft) author=\(.author | v) merged_by=\(.merged_by | v) \"\(.title)\"" end)), # merged-ok: a live PR merge state printed as a report fact, never a deletion proof (.repos[] | if .is_repo != true then "repo \(.path) NOT A REPO: \(.error | v)" else "repo \(.path) slug=\(.github_slug | v) default=\(.default_branch | v) branch=\(.checkout.branch | v) ahead=\(.checkout.ahead | v) behind=\(.checkout.behind | v) dirty=\(.checkout.dirty_files | length) index_lock=\(.checkout.index_lock.present) fetch=\"\(.fetch_error | v)\"", @@ -765,7 +765,7 @@ _session_summary_text() { ((.checks.latest // [])[] | select(((.conclusion // "") | ascii_upcase) as $c | $c != "SUCCESS" and $c != "SKIPPED" and $c != "NEUTRAL") | " check \(.name) \(.status // "-") \(.conclusion // "pending")")), (.pull_requests as $p | $p.merged_recent[]? | . as $m | ([$p.deploys[]? | select(.pr == $m.number)][0] // {}) as $d - | " merged #\(.number) at=\(.mergedAt | v) merge=\(.merge_sha | sha) deploy=\($d.state // "-") head=\(.headRefName | v) \"\(.title // "")\""), # merged-ok: a live PR merge state printed as a report fact, never a deletion proof + | " merged #\(.number) at=\(.mergedAt | v) merge=\(.merge_sha | sha) deploy=\($d.state // "-") author=\(.author | v) merged_by=\(.merged_by | v) head=\(.headRefName | v) \"\(.title // "")\""), # merged-ok: a live PR merge state printed as a report fact, never a deletion proof (.sweep | if .format == "json" then (.document.repos[]? | " sweep " + ((.rows // []) | group_by(.verdict) | map("\(.[0].verdict)=\(length)") | join(" ") | if . == "" then "rows=0" else . end) + (if .error then " error=\"\(.error)\"" else "" end), diff --git a/tests/test-wrap-report-lint.sh b/tests/test-wrap-report-lint.sh index 046e5a8c..a04566bf 100755 --- a/tests/test-wrap-report-lint.sh +++ b/tests/test-wrap-report-lint.sh @@ -18,6 +18,17 @@ LINT="$KIT_DIR/lib/wrap/report-lint.sh" # rule gets its own cases further down. _report() { printf '## Wrap: t\n\n%s\n\n**Built:** NOTHING: no candidates\n\n**Seam:** NOTHING: no seam configured\n\n**What happened**\n- %s\n' "$1" "${2:-body}"; } +# The line budget: a first wrap report has at most 40 non-blank lines. +_pad() { _report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' | awk -v n="$1" '{print} END {for (i = 1; i <= n; i++) print "- fact " i}'; } +base_lines="$(_pad 0 | grep -c '[^[:space:]]')" +out="$(_pad $((40 - base_lines)) | bash "$LINT" 2>&1)"; rc=$? +chk "a wrap report of exactly 40 non-blank lines passes the budget" "$rc" +out="$(_pad $((41 - base_lines)) | bash "$LINT" 2>&1)"; rc=$? +chk "a wrap report of 41 non-blank lines fails the budget" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" +chk_has "the budget finding names the count and the budget" "$out" "the report has 41 non-blank lines; the budget is 40" +out="$(_pad 60 | sed '1s/^## Wrap:.*/## Follow-through: t/' | bash "$LINT" 2>&1)" +chk_no "a follow-through report is not held to the wrap budget" "$out" "non-blank lines; the budget" + # The needs-you walk: a first wrap report's NOTHING names what was walked. out="$(_report 'āœ… **Needs you:** NOTHING' | bash "$LINT" 2>&1)"; rc=$? chk "a bare NOTHING in a wrap report fails the lint" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" diff --git a/tests/test-wrap-session.sh b/tests/test-wrap-session.sh index fc6db55f..0937e4df 100755 --- a/tests/test-wrap-session.sh +++ b/tests/test-wrap-session.sh @@ -81,11 +81,14 @@ esac exec "${GH_DEPLOY_DELEGATE}" "$@" GHDEP chmod +x "$TMPD/gh-deploy/gh" -merged='[{"number":9,"title":"landed","headRefName":"feat/landed","mergedAt":"2026-01-02T00:00:00Z","mergeCommit":{"oid":"abc123"},"author":{"login":"me"}}]' +merged='[{"number":9,"title":"landed","headRefName":"feat/landed","mergedAt":"2026-01-02T00:00:00Z","mergeCommit":{"oid":"abc123"},"author":{"login":"me"},"mergedBy":{"login":"bot-y"}}]' out="$(PATH="$TMPD/gh-deploy:$PATH" GH_DEPLOY_DELEGATE="$TMPD/stub/gh" GH_STUB_MERGED_ALL="$merged" WRAP_SESSION_WRAP_BIN="$fake" "$WRAP" session --json "$dep" 2>/dev/null)"; rc=$? chk "the deploy gather exits 0" "$rc" jqok "a successful check-run on the merge sha is deploy success" "$out" '.repos[0].pull_requests.merged_recent[0].number == 9 and .repos[0].pull_requests.deploys[0].state == "success" and .repos[0].pull_requests.deploys[0].merge_sha == "abc123"' jqok "the GitHub slug and PR links are first-class fields" "$out" '.repos[0].github_slug == "acme/widgets" and .repos[0].pull_requests.open_own[0].url == "https://github.com/acme/widgets/pull/7" and .repos[0].pull_requests.merged_recent[0].url == "https://github.com/acme/widgets/pull/9"' +jqok "a recent merged PR carries its live author and merger" "$out" '.repos[0].pull_requests.merged_recent[0] | .author == "me" and .merged_by == "bot-y" and .title == "landed"' +sum="$(PATH="$TMPD/gh-deploy:$PATH" GH_DEPLOY_DELEGATE="$TMPD/stub/gh" GH_STUB_MERGED_ALL="$merged" WRAP_SESSION_WRAP_BIN="$fake" "$WRAP" session --summary "$dep" 2>/dev/null)" +chk_has "the summary names a merged PR's author and merger" "$sum" "merged #9 at=2026-01-02T00:00:00Z merge=abc123 deploy=success author=me merged_by=bot-y" # =========================================================================== echo "=== fallback and degraded gh states ===" @@ -274,7 +277,7 @@ export TMPD_STUB_GH="$TMPD/stub/gh" GQL_STUB_CALLS="$TMPD/gql.calls" gather() { PATH="$TMPD/gh-gql:$PATH" WRAP_SESSION_WRAP_BIN="$fake" "$WRAP" session "$@"; } gql_doc='{"data":{ - "r0":{"p6190":{"number":6190,"title":"feat: verbatim post","url":"https://github.com/acme/ops/pull/6190","state":"MERGED","merged":true,"mergedAt":"2026-11-26T04:30:12Z","mergeCommit":{"oid":"eb792834f92d0000000000000000000000000000"},"headRefName":"feat/post","baseRefName":"main","isDraft":false,"author":{"login":"me"}}, + "r0":{"p6190":{"number":6190,"title":"feat: verbatim post","url":"https://github.com/acme/ops/pull/6190","state":"MERGED","merged":true,"mergedAt":"2026-11-26T04:30:12Z","mergeCommit":{"oid":"eb792834f92d0000000000000000000000000000"},"headRefName":"feat/post","baseRefName":"main","isDraft":false,"author":{"login":"me"},"mergedBy":{"login":"operator-x"}}, "p7":{"number":7,"title":"still open","url":"https://github.com/acme/ops/pull/7","state":"OPEN","merged":false,"mergedAt":null,"mergeCommit":null,"headRefName":"feat/x","baseRefName":"main","isDraft":false,"author":{"login":"me"}}, "p999":null}, "r1":{"p1051":{"number":1051,"title":"fix(link-bot): same chat","url":"https://github.com/acme/dots/pull/1051","state":"MERGED","merged":true,"mergedAt":"2026-11-26T04:47:05Z","mergeCommit":{"oid":"4cf53e1aee370000000000000000000000000000"},"headRefName":"fix/same-chat","baseRefName":"main","isDraft":false,"author":{"login":"me"}}}}, @@ -293,6 +296,9 @@ chk_has "the query aliases the second repo" "$q" 'r1: repository(owner: "acme", chk_has "the query reads the merge state live" "$q" "merged mergedAt mergeCommit { oid statusCheckRollup { state } } headRefName" jqok "every ref is a row, duplicates folded, in input order" "$out" '[.named_prs.rows[].ref] == ["acme/ops#6190","acme/ops#7","acme/dots#1051","acme/ops#999"]' jqok "a merged PR carries state, merged, mergedAt, merge commit and head branch" "$out" '.named_prs.rows[0] | .state == "MERGED" and .merged == true and .merged_at == "2026-11-26T04:30:12Z" and .merge_sha == "eb792834f92d0000000000000000000000000000" and .head_branch == "feat/post" and .error == null' +jqok "a named PR carries its live title, author and merger" "$out" '.named_prs.rows[0] | .title == "feat: verbatim post" and .author == "me" and .merged_by == "operator-x"' +jqok "an unmerged named PR has no merger" "$out" '.named_prs.rows[1].merged_by == null' +chk_has "the batched query asks for the merger" "$(cat "$GQL_STUB_CALLS")" "mergedBy { login }" jqok "an open PR reads OPEN, never a cached merged state" "$out" '.named_prs.rows[1] | .state == "OPEN" and .merged == false and .merge_sha == null' jqok "a URL ref resolves like owner/name#n" "$out" '.named_prs.rows[2] | .number == 1051 and .state == "MERGED"' jqok "an unresolvable PR stays a row with GitHub's error" "$out" '.named_prs.rows[3] | (.error | test("Could not resolve")) and .state == null' @@ -337,6 +343,7 @@ chk_has "config knobs are one line" "$sum" "config distill=" chk_has "config carries the follow mode" "$sum" "follow_mode=" chk_has "the activity log has its line" "$sum" "activity_log configured=" chk_has "a named merged PR prints its live state and merge commit" "$sum" "pr acme/ops#6190 state=MERGED merged=true merged_at=2026-11-26T04:30:12Z merge=eb792834f92d merge_checks=- head=feat/post" +chk_has "a named merged PR prints its author and merger" "$sum" "author=me merged_by=operator-x \"feat: verbatim post\"" chk_has "a named PR GitHub cannot resolve prints ERROR" "$sum" "pr acme/ops#999 ERROR Could not resolve" chk_has "the repo line carries branch, counts and fetch state" "$sum" "default=main branch=main ahead=0 behind=0 dirty=1 index_lock=false" chk_has "the untracked board dir is a dirty line" "$sum" "dirty ?? _meta/" From 9328d65f56eb3789e6934229fac0c6177755d344 Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 14:14:13 +0700 Subject: [PATCH 18/19] fix(wrap): the report lint holds every wrap-shaped report; cd chains fold Review round 3 fixes; the command's report rules are unchanged. - report-lint.sh: the line budget and the walked-NOTHING rule now hold for every report except `## Follow-through:` and `## Harvest sweep:`, so a drifted heading (`## wrap:`, `## Wrap `, an extra heading above it, or none) no longer switches them off. - report-lint.sh: a bullet or lettered item outside a fence holds at most 3 sentences, so one packed line cannot dodge the budget. - wrap session: cd targets fold in order (`cd /repoB && cd sub` lands in repoB/sub), for URL-less merges and for repo discovery, where a git -C target resolves against the folded directory. ## How I verified it bash tests/test-wrap-session.sh -> test-wrap-session: all 159 passed bash tests/test-wrap-report-lint.sh -> test-wrap-report-lint: all 180 passed on a3a02f04's scripts -> 1 and 11 of the new cases fail --- docs/verification/wrap-cut-call.md | 34 ++++++++++++++++++++++++++++++ lib/wrap/report-lint.sh | 24 +++++++++++++++++++-- lib/wrap/wrap-session.sh | 4 ++-- tests/test-wrap-report-lint.sh | 16 ++++++++++++++ tests/test-wrap-session.sh | 5 ++++- 5 files changed, 78 insertions(+), 5 deletions(-) diff --git a/docs/verification/wrap-cut-call.md b/docs/verification/wrap-cut-call.md index 35da47d4..b87b410e 100644 --- a/docs/verification/wrap-cut-call.md +++ b/docs/verification/wrap-cut-call.md @@ -209,6 +209,40 @@ All harvest sweep tests passed. Verdict: PASS ``` +### Review round 3 fixes (after `a3a02f04`) + +The command's report rules are unchanged; a holdout is scoring them. + +- MEDIUM, `lib/wrap/report-lint.sh`: the wrap rules (the 40-line budget and the walked `NOTHING`) now hold for every report except `## Follow-through:` and `## Harvest sweep:`. Before, they applied only when the first heading was exactly `## Wrap:`, so `## wrap:`, `## Wrap `, an extra heading above, or no heading passed a 60-fact report. +- LOW, the same file: in a wrap report, a bullet or a lettered item outside a code fence holds at most 3 sentences, so one packed line cannot dodge the line budget. +- LOW, `lib/wrap/wrap-session.sh`: `cd` targets fold in order, so `cd /repoB && cd sub && gh pr merge 8` credits repoB. Repo discovery folds the same way, and a `git -C` target resolves against the folded directory. + +```text +Command: bash tests/test-wrap-session.sh; bash tests/test-wrap-report-lint.sh (in a git archive copy of a3a02f04 with the new suites) +Exit: 1 +Output: + FAIL an absolute-then-relative cd chain credits the absolute repo +test-wrap-session: 158 passed, 1 FAILED of 159 + FAIL heading edit '1s/^## Wrap:/## wrap:/': a 60-fact report still fails the budget + FAIL heading edit '1d': a 60-fact report still fails the budget + FAIL a lower-case heading still owes the walked NOTHING + FAIL one bullet packing 60 sentences fails +test-wrap-report-lint: 169 passed, 11 FAILED of 180 +Verdict: RED, as expected +``` + +```text +Command: bash tests/test-wrap-session.sh; bash tests/test-wrap-report-lint.sh; bash tests/test-harvest-sweep.sh; bash tests/test-wrap-deploy.sh; bash tests/test-wrap-ci.sh +Exit: 0 +Output: +test-wrap-session: all 159 passed +test-wrap-report-lint: all 180 passed +All harvest sweep tests passed. +test-wrap-deploy: all 176 passed +test-wrap-ci: all 214 passed +Verdict: PASS +``` + ## Not proven locally - The full suite (`bash tests/run-all.sh`) did not run locally: the host was loaded. CI's `--changed` run passed. diff --git a/lib/wrap/report-lint.sh b/lib/wrap/report-lint.sh index 8299beaf..7da8b848 100755 --- a/lib/wrap/report-lint.sh +++ b/lib/wrap/report-lint.sh @@ -78,8 +78,11 @@ sweep_report=0 first_h2="$(printf '%s\n' "$input" | grep -m1 '^## ' || true)" case "$first_h2" in '## Follow-through:'*) follow_report=1 ;; esac case "$first_h2" in '## Harvest sweep:'*) sweep_report=1 ;; esac -wrap_report=0 -case "$first_h2" in '## Wrap:'*) wrap_report=1 ;; esac +# Every report that is not one of the two known other shapes is held to the first wrap report's +# rules (the line budget, the walked NOTHING, the bullet cap), so a drifted heading (`## wrap:`, +# `## Wrap `, an extra heading above it, or none) cannot switch them off. +wrap_report=1 +[ "$follow_report" = 1 ] || [ "$sweep_report" = 1 ] && wrap_report=0 # PR numbers named by `Needs you` items that open with REVIEW, space-separated, filled by the @@ -96,6 +99,23 @@ if [ "$wrap_report" = 1 ] && [ "$report_lines" -gt "$REPORT_MAX_LINES" ]; then echo "line 0: the report has ${report_lines} non-blank lines; the budget is ${REPORT_MAX_LINES}. Cut repeated facts and merge rows" >&2 findings=$((findings + 1)) fi +# One fact per bullet: a bullet or a lettered item outside a code fence holds at most +# BULLET_MAX_SENTENCES sentences, so the line budget cannot be dodged by packing one line. +BULLET_MAX_SENTENCES=3 +if [ "$wrap_report" = 1 ]; then + _b_fence=0; _b_lineno=0 + while IFS= read -r _b_line; do + _b_lineno=$((_b_lineno + 1)) + case "$_b_line" in '```'*) _b_fence=$((1 - _b_fence)); continue ;; esac + [ "$_b_fence" = 1 ] && continue + case "$_b_line" in '- '*|[a-z].\ *) ;; *) continue ;; esac + _b_n="$(printf '%s\n' "$_b_line" | grep -oE '[.!?]([[:space:]]|$)' | wc -l | tr -d ' ')" + if [ "$_b_n" -gt "$BULLET_MAX_SENTENCES" ]; then + echo "line ${_b_lineno}: one bullet holds ${_b_n} sentences; the cap is ${BULLET_MAX_SENTENCES}, one fact per bullet" >&2 + findings=$((findings + 1)) + fi + done <<< "$input" +fi # Walk the report. `in_block` is on between the `Needs you` header and the next bold section # header, so only that section is judged; a `What happened` sentence may say anything. lineno=0 diff --git a/lib/wrap/wrap-session.sh b/lib/wrap/wrap-session.sh index a38c9048..d8de71fc 100644 --- a/lib/wrap/wrap-session.sh +++ b/lib/wrap/wrap-session.sh @@ -600,7 +600,7 @@ _session_transcript_json() { | select($c | test("https://github\\.com/[^ ]+/pull/[0-9]+") | not) | ([$c | scan("(?:--repo|-R)[ =]+([A-Za-z0-9][A-Za-z0-9-]*/[A-Za-z0-9_.-]+)") | .[0]] | first // "") as $repo | ([$c | scan("gh +pr +(?:merge|ready|close) +([0-9]+)") | .[0]] | first // "") as $n - | ([$c | sub("gh +pr +(?:merge|ready|close)[\\s\\S]*$"; "") | scan("\\bcd\\s+(\"[^\"]+\"|'"'"'[^'"'"']+'"'"'|[^\\s;&|)]+)") | .[0]] | if length == 0 then $cwd else (last | abs($cwd)) end) as $dir + | ([$c | sub("gh +pr +(?:merge|ready|close)[\\s\\S]*$"; "") | scan("\\bcd\\s+(\"[^\"]+\"|'"'"'[^'"'"']+'"'"'|[^\\s;&|)]+)") | .[0]] | reduce .[] as $t ($cwd; . as $acc | $t | abs($acc))) as $dir | if $repo != "" and $n != "" then "https://github.com/\($repo)/pull/\($n)" else "\u0001BARE\u001f\($dir)\u001f\($repo)\u001f\($n)\u001f\($br)" end) ' "$clean" 2>/dev/null)" @@ -642,7 +642,7 @@ EOF_SESSION_BARE (select($cwd != "") | $cwd), (.message.content[]? | select(type == "object" and .type == "tool_use") | .input | ((.file_path // .notebook_path // empty | abs($cwd)), - ((.command // "") | [scan("(?:git\\s+-C|\\bcd)\\s+(\"[^\"]+\"|'"'"'[^'"'"']+'"'"'|[^\\s;&|)]+)") | .[0] | abs($cwd)] | .[]))) + ((.command // "") | [scan("(git\\s+-C|\\bcd)\\s+(\"[^\"]+\"|'"'"'[^'"'"']+'"'"'|[^\\s;&|)]+)") ] | reduce .[] as $m ({acc:$cwd, out:[]}; . as $st | ($m[1] | abs($st.acc)) as $d | if ($m[0] | startswith("cd")) then {acc:$d, out:($st.out + [$d])} else .out += [$d] end) | .out[]))) ' "$clean" 2>/dev/null | tr -d "\"'" | sed "s#^~/#$HOME/#" | grep '^/' | awk '!seen[$0]++')" unresolved="$(_session_lines_json < "$unknown")"; [ -n "$unresolved" ] || unresolved='[]' rm -f "$clean" "$lead_clean" "$unknown" diff --git a/tests/test-wrap-report-lint.sh b/tests/test-wrap-report-lint.sh index a04566bf..e46693f1 100755 --- a/tests/test-wrap-report-lint.sh +++ b/tests/test-wrap-report-lint.sh @@ -29,6 +29,22 @@ chk_has "the budget finding names the count and the budget" "$out" "the report h out="$(_pad 60 | sed '1s/^## Wrap:.*/## Follow-through: t/' | bash "$LINT" 2>&1)" chk_no "a follow-through report is not held to the wrap budget" "$out" "non-blank lines; the budget" +# The wrap rules hold for every report but the two known other shapes: a drifted heading, +# an extra heading above, or none cannot switch off the budget or the walked NOTHING. +for _h in '1s/^## Wrap:/## wrap:/' '1s/^## Wrap: t/## Wrap t/' '1s/^/## Summary\n\n/' '1d'; do + out="$(_pad 60 | sed "$_h" | bash "$LINT" 2>&1)"; rc=$? + chk "heading edit '$_h': a 60-fact report still fails the budget" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" + chk_has "heading edit '$_h': the budget finding fires" "$out" "the budget is 40" +done +out="$(_report 'āœ… **Needs you:** NOTHING' | sed '1s/^## Wrap:/## wrap:/' | bash "$LINT" 2>&1)"; rc=$? +chk "a lower-case heading still owes the walked NOTHING" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" +# One fact per bullet: a bullet holds at most 3 sentences. +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' "$(for i in $(seq 1 60); do printf 'Fact %s. ' "$i"; done)" | bash "$LINT" 2>&1)"; rc=$? +chk "one bullet packing 60 sentences fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" +chk_has "the bullet finding names the cap" "$out" "one bullet holds 60 sentences; the cap is 3" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' 'One fact. Its proof quotes output. The PR is #7.' | bash "$LINT" 2>&1)"; rc=$? +chk "a bullet of 3 sentences passes" "$rc" + # The needs-you walk: a first wrap report's NOTHING names what was walked. out="$(_report 'āœ… **Needs you:** NOTHING' | bash "$LINT" 2>&1)"; rc=$? chk "a bare NOTHING in a wrap report fails the lint" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" diff --git a/tests/test-wrap-session.sh b/tests/test-wrap-session.sh index 0937e4df..48ac1ffa 100755 --- a/tests/test-wrap-session.sh +++ b/tests/test-wrap-session.sh @@ -475,9 +475,12 @@ mkdir -p "$tx5_p/sub" "$tx6_p/sub" "$TMPD/plain-dir" tr5="$TMPD/projects/sess5.jsonl" jq -cn --arg cwd "$tx5_p" '{type:"assistant",timestamp:"2026-11-27T04:00:00Z",cwd:$cwd,message:{content:[{type:"tool_use",id:"r1",name:"Bash",input:{command:"cd sub && gh pr merge 5 --squash; cd /tmp"}}]}}' > "$tr5" jq -cn --arg cwd "$TMPD/plain-dir" '{type:"assistant",timestamp:"2026-11-27T04:01:00Z",cwd:$cwd,message:{content:[{type:"tool_use",id:"r2",name:"Bash",input:{command:"cd nowhere && gh pr merge 6 --squash"}}]}}' >> "$tr5" +# A chain folds in order: `cd /repoB && cd sub` lands in repoB/sub, never in the record's repo. +jq -cn --arg cwd "$tx5_p" --arg c "cd $tx6_p && cd sub && gh pr merge 8 --squash" '{type:"assistant",timestamp:"2026-11-27T04:02:00Z",cwd:$cwd,message:{content:[{type:"tool_use",id:"r3",name:"Bash",input:{command:$c}}]}}' >> "$tr5" out="$(cd "$tx6_p" && GQL_STUB_JSON='{"data":{}}' gather --json --transcript "$tr5" 2>/dev/null)" +jqok "an absolute-then-relative cd chain credits the absolute repo" "$out" '(.transcript.acted_prs | index("acme/unrelated#8") != null) and (.transcript.acted_prs | index("acme/session-repo#8") == null)' jqok "a relative cd merge credits the record's repo" "$out" '.transcript.acted_prs | index("acme/session-repo#5") != null' -jqok "a relative cd merge never credits the wrap's own repo" "$out" '[.transcript.acted_prs[] | select(startswith("acme/unrelated"))] == []' +jqok "a relative cd merge never credits the wrap's own repo" "$out" '(.transcript.acted_prs | index("acme/unrelated#5")) == null' jqok "a merge whose cd lands in no repo is reported unresolved, not credited" "$out" '(.transcript.unresolved_merges | length) == 1 and (.transcript.unresolved_merges[0] | test("gh pr merge 6 in .*plain-dir/nowhere"))' # =========================================================================== From 2829c60e9ce700ae9024db0341d70f8c46f3327c Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 14:29:39 +0700 Subject: [PATCH 19/19] fix(wrap): cap a report bullet by characters, not sentences The per-bullet sentence count counted the `a. ` marker and abbreviations, so the Needs-you template `a. . . .` failed every report with an owner item. A bullet or lettered item outside a code fence is now capped at 400 characters; the template with a real 321-character command fits. commands/wrap.md names the second report's heading as `## Follow-through: `, the shape the lint exempts (heading text only; the report rules are unchanged). ## How I verified it bash tests/test-wrap-report-lint.sh -> test-wrap-report-lint: all 184 passed on 9328d65f's report-lint.sh -> 180 passed, 4 FAILED of 184 --- commands/wrap.md | 2 +- docs/verification/wrap-cut-call.md | 27 +++++++++++++++++++++++++++ lib/wrap/report-lint.sh | 15 +++++++++------ tests/test-wrap-report-lint.sh | 15 +++++++++++++-- 4 files changed, 50 insertions(+), 9 deletions(-) diff --git a/commands/wrap.md b/commands/wrap.md index fdfd9371..a9c7ce13 100644 --- a/commands/wrap.md +++ b/commands/wrap.md @@ -156,7 +156,7 @@ A full-lane worker reserves the spec number, writes and commits the spec with gr 4. Inside this background follow-through, `gh pr checks --watch` may wait for checks; it never holds the first report. Merge only through the PR gate as `bin/wrap merge --apply --pr ` (a stopped repo adds `--no-pull`): it merges only an own PR. A SKIP or TREE MISMATCH leaves it OPEN. 5. Tidy through the own-scope dry run, then apply; a stopped repo adds `--no-pull`. -Print the second report only when follow-through ran, in the same grammar under `### Step 10: follow-through:`. It has no `**Seam:**` line. Its `Needs you` lists only new review items or blockers. Record `bash lib/gate/gate-ledger.sh record wrap-follow ran` and close `bash lib/gate/gate-ledger.sh outcome wrap-follow end`. +Print the second report only when follow-through ran, in the same grammar under `## Follow-through: `. It has no `**Seam:**` line. Its `Needs you` lists only new review items or blockers. Record `bash lib/gate/gate-ledger.sh record wrap-follow ran` and close `bash lib/gate/gate-ledger.sh outcome wrap-follow end`. ## What this command does NOT do diff --git a/docs/verification/wrap-cut-call.md b/docs/verification/wrap-cut-call.md index b87b410e..0ed80220 100644 --- a/docs/verification/wrap-cut-call.md +++ b/docs/verification/wrap-cut-call.md @@ -243,6 +243,33 @@ test-wrap-ci: all 214 passed Verdict: PASS ``` +### Review round 4 fixes (after `9328d65f`) + +- HIGH, `lib/wrap/report-lint.sh`: the per-bullet sentence count is gone. It counted the `a. ` marker and abbreviations, so the Needs-you template `a. . . .` failed every report with an owner item. A bullet or lettered item outside a code fence is now capped at 400 characters. The template with a real 321-character command fits. +- LOW, `commands/wrap.md`: the second report's heading is now `## Follow-through: `, the shape the lint exempts. The old text named `### Step 10: follow-through:`. Only the heading text changed; the report rules did not. + +```text +Command: bash tests/test-wrap-report-lint.sh (in a git archive copy of 9328d65f with the new suite) +Exit: 1 +Output: + FAIL the bullet finding names the cap + FAIL the Needs-you template with a 321-character real command passes the lint + FAIL a bullet with abbreviations and four short sentences passes + FAIL a 403-character bullet fails the cap +test-wrap-report-lint: 180 passed, 4 FAILED of 184 +Verdict: RED, as expected +``` + +```text +Command: bash tests/test-wrap-report-lint.sh; bash tests/test-harvest-sweep.sh; bash tests/test-meta-spec-depth.sh +Exit: 0 +Output: +test-wrap-report-lint: all 184 passed +All harvest sweep tests passed. +All meta tests passed. +Verdict: PASS +``` + ## Not proven locally - The full suite (`bash tests/run-all.sh`) did not run locally: the host was loaded. CI's `--changed` run passed. diff --git a/lib/wrap/report-lint.sh b/lib/wrap/report-lint.sh index 7da8b848..7df65e3d 100755 --- a/lib/wrap/report-lint.sh +++ b/lib/wrap/report-lint.sh @@ -99,9 +99,12 @@ if [ "$wrap_report" = 1 ] && [ "$report_lines" -gt "$REPORT_MAX_LINES" ]; then echo "line 0: the report has ${report_lines} non-blank lines; the budget is ${REPORT_MAX_LINES}. Cut repeated facts and merge rows" >&2 findings=$((findings + 1)) fi -# One fact per bullet: a bullet or a lettered item outside a code fence holds at most -# BULLET_MAX_SENTENCES sentences, so the line budget cannot be dodged by packing one line. -BULLET_MAX_SENTENCES=3 +# One fact per bullet: a bullet or a lettered item outside a code fence is at most +# BULLET_MAX_CHARS characters, so the line budget cannot be dodged by packing one line. A +# character cap, not a sentence count: a lettered marker (`a. `) and abbreviations (`e.g. `) +# would count as sentences, and the Needs-you template `a. . . .` with a +# real command fits in 400. +BULLET_MAX_CHARS=400 if [ "$wrap_report" = 1 ]; then _b_fence=0; _b_lineno=0 while IFS= read -r _b_line; do @@ -109,9 +112,9 @@ if [ "$wrap_report" = 1 ]; then case "$_b_line" in '```'*) _b_fence=$((1 - _b_fence)); continue ;; esac [ "$_b_fence" = 1 ] && continue case "$_b_line" in '- '*|[a-z].\ *) ;; *) continue ;; esac - _b_n="$(printf '%s\n' "$_b_line" | grep -oE '[.!?]([[:space:]]|$)' | wc -l | tr -d ' ')" - if [ "$_b_n" -gt "$BULLET_MAX_SENTENCES" ]; then - echo "line ${_b_lineno}: one bullet holds ${_b_n} sentences; the cap is ${BULLET_MAX_SENTENCES}, one fact per bullet" >&2 + _b_line="${_b_line%$'\r'}" + if [ "${#_b_line}" -gt "$BULLET_MAX_CHARS" ]; then + echo "line ${_b_lineno}: one bullet is ${#_b_line} characters; the cap is ${BULLET_MAX_CHARS}, one fact per bullet" >&2 findings=$((findings + 1)) fi done <<< "$input" diff --git a/tests/test-wrap-report-lint.sh b/tests/test-wrap-report-lint.sh index e46693f1..2f053770 100755 --- a/tests/test-wrap-report-lint.sh +++ b/tests/test-wrap-report-lint.sh @@ -38,12 +38,23 @@ for _h in '1s/^## Wrap:/## wrap:/' '1s/^## Wrap: t/## Wrap t/' '1s/^/## Summary\ done out="$(_report 'āœ… **Needs you:** NOTHING' | sed '1s/^## Wrap:/## wrap:/' | bash "$LINT" 2>&1)"; rc=$? chk "a lower-case heading still owes the walked NOTHING" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" -# One fact per bullet: a bullet holds at most 3 sentences. +# One fact per bullet: a bullet or lettered item is at most 400 characters. out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' "$(for i in $(seq 1 60); do printf 'Fact %s. ' "$i"; done)" | bash "$LINT" 2>&1)"; rc=$? chk "one bullet packing 60 sentences fails" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" -chk_has "the bullet finding names the cap" "$out" "one bullet holds 60 sentences; the cap is 3" +chk_has "the bullet finding names the cap" "$out" "characters; the cap is 400, one fact per bullet" out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' 'One fact. Its proof quotes output. The PR is #7.' | bash "$LINT" 2>&1)"; rc=$? chk "a bullet of 3 sentences passes" "$rc" +# The Needs-you template with a long real command, and abbreviations, stay under the cap. +tmpl='a. RUN gh auth refresh. The token expired and only you hold the 2FA device, e.g. on your phone. Run gh auth refresh -h github.com -s repo,workflow,read:org, then bin/wrap session --summary --transcript ~/.claude/projects/-Users-x-workspace-org-repo/0123abcd-4567-89ef-0123-456789abcdef.jsonl --mark-dir /tmp/wrap-scratch.' +out="$(_report "šŸ”“ **Needs you:** +$tmpl" | bash "$LINT" 2>&1)"; rc=$? +chk "the Needs-you template with a ${#tmpl}-character real command passes the lint" "$rc" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' 'Pruned stale refs, e.g. feat/x, feat/y, etc. in two repos. All green. Proof: 4 removed, 0 kept.' | bash "$LINT" 2>&1)"; rc=$? +chk "a bullet with abbreviations and four short sentences passes" "$rc" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' "$(printf 'x%.0s' $(seq 1 401))" | bash "$LINT" 2>&1)"; rc=$? +chk "a 403-character bullet fails the cap" "$([ "$rc" -eq 1 ] && echo 0 || echo 1)" +out="$(_report 'āœ… **Needs you:** NOTHING (walked: digest 3 replies, miner 1 action)' "$(printf 'x%.0s' $(seq 1 398))" | bash "$LINT" 2>&1)"; rc=$? +chk "a 400-character bullet passes the cap" "$rc" # The needs-you walk: a first wrap report's NOTHING names what was walked. out="$(_report 'āœ… **Needs you:** NOTHING' | bash "$LINT" 2>&1)"; rc=$?