From d089df7e9f9e73697c440980fce13090a1ecffb0 Mon Sep 17 00:00:00 2001 From: vitya Date: Sun, 24 May 2026 23:41:26 +0300 Subject: [PATCH] fix(session-handoff): PowerShell hook body char count [v0.3.1] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `(& git log -1 --format='%b')` in PowerShell collapses multi-line subprocess output into string[]. The threshold check used `$body.Length` which on a string[] returns the line count, not char count — so the body>200 condition was effectively comparing "more than 200 lines", which is much harder to meet. Files-count saves it in practice for big commits, but small-file big-message commits were under-detected. Fix: join the array back into a single string with `-join "`n"` before measuring length. Verified via stdin-pipe smoke against current HEAD: body chars now report 1255 (vs 29 before — the line count). POSIX `.sh` variant unaffected — `$()` collapses output and `${#var}` is char count. Bump 0.3.0 → 0.3.1 PATCH (bugfix, no behavior contract change). Co-Authored-By: Claude Opus 4.7 (1M context) --- .tasks/STATUS.md | 25 ++++++------------- .tasks/session-handoff-posttooluse-hook.md | 7 +++--- skills/session-handoff/SKILL.md | 2 +- .../session-handoff/hooks/commit-detector.ps1 | 7 ++++-- 4 files changed, 17 insertions(+), 24 deletions(-) diff --git a/.tasks/STATUS.md b/.tasks/STATUS.md index 0f9cb64..5131eb8 100644 --- a/.tasks/STATUS.md +++ b/.tasks/STATUS.md @@ -1,5 +1,5 @@ # Task Board -_Updated: 2026-05-24 (session-handoff: 3 baseline 🟢, posttooluse-hook + existing-projects-upgrade → 🔴.)_ +_Updated: 2026-05-24 (session-handoff: 4 закрыто 🟢 (install/template-extend/hermes/posttooluse-hook); existing-projects-upgrade → 🔴.)_ + --- diff --git a/.tasks/session-handoff-posttooluse-hook.md b/.tasks/session-handoff-posttooluse-hook.md index 301eb2f..504c080 100644 --- a/.tasks/session-handoff-posttooluse-hook.md +++ b/.tasks/session-handoff-posttooluse-hook.md @@ -30,9 +30,10 @@ - [x] Update SKILL.md body — When-to-use mentions hook as opt-in alternative - [x] Bump SKILL.md 0.2.1 → 0.3.0 (MINOR — new capability) - [x] Reinstall via scripts/install.ps1 -- [ ] stdin-pipe smoke (substantive HEAD + trivial HEAD) -- [ ] STATUS.md → 🟢 (partial: stdin smoke ✓, live-hook deferred) -- [ ] commit +- [x] stdin-pipe smoke (6 scenarios): substantive HEAD ✓ emits JSON; --amend / ls / empty / malformed / failed-commit ✓ silent skip +- [x] discover + fix PS bug: `git log %b` → string[], `.Length` was line count; `-join "`n"` fix; PATCH bump 0.3.0 → 0.3.1 +- [x] STATUS.md → 🟢 (partial: stdin smoke ✓, live-hook deferred to separate session) +- [ ] commit (next) ## Notes Live-hook enable + e2e validation = separate task / separate session. Adding hook to settings.json in this active session would fire on every git commit done here, including the closure commit itself — meta-feedback loop best avoided. diff --git a/skills/session-handoff/SKILL.md b/skills/session-handoff/SKILL.md index 742a3ee..ea5e7a6 100644 --- a/skills/session-handoff/SKILL.md +++ b/skills/session-handoff/SKILL.md @@ -1,6 +1,6 @@ --- name: session-handoff -version: 0.3.0 +version: 0.3.1 description: "Sliding handoff between CC sessions via .tasks/NEXT_SESSION.md. Read on session start: orient agent, ask user before action. Write on session-end phrase or substantive commit. Session-end phrases: «завершаем сессию», «сворачиваемся», «закругляемся», «wrap up session», «end session», «we're done for now». Trigger-line in CLAUDE.md: `session handoff: read on start, write on end`. Skip task-zone phrases: «закрываем эту таску», «pause», «отбой», «разбегаемся»." --- diff --git a/skills/session-handoff/hooks/commit-detector.ps1 b/skills/session-handoff/hooks/commit-detector.ps1 index 6f5b796..8e8e9dc 100644 --- a/skills/session-handoff/hooks/commit-detector.ps1 +++ b/skills/session-handoff/hooks/commit-detector.ps1 @@ -43,7 +43,9 @@ if ($inside -ne 'true') { exit 0 } # Parse last commit $subject = (& git -C $cwd log -1 --format='%s').Trim() -$body = (& git -C $cwd log -1 --format='%b') +# PowerShell collapses multi-line subprocess output into string[] — join back so +# .Length below is char count, not line count. +$body = ((& git -C $cwd log -1 --format='%b') -join "`n") $files = ((& git -C $cwd diff-tree --no-commit-id --name-only -r HEAD) | Measure-Object).Count # Trivial-prefix check (Conventional Commits prefix before optional scope + colon) @@ -52,10 +54,11 @@ $trivial = @('meta','docs','style','chore') if ($trivial -contains $prefix) { exit 0 } if ($subject -match 'fix\s+typo') { exit 0 } -# Threshold check +# Threshold check (chars for body, count for files) $bodyLen = if ($body) { $body.Length } else { 0 } if ($bodyLen -le 200 -and $files -le 3) { exit 0 } + # Substantive — emit JSON $msg = "Substantive commit detected on " + $cwd + ": ``" + $subject + "`` (" + $files + " files changed, body " + $bodyLen + " chars). Consider invoking session-handoff write-mode to update .tasks/NEXT_SESSION.md."