fix: strip AI reasoning blocks from commit messages
Adds a `_strip_think` function using `awk` to buffer stdin and track the last `</think>` tag, emitting only the subsequent content. This utility is now piped after `aichat` calls to remove AI reasoning blocks before commit message generation. Also applies minor whitespace and indentation adjustments throughout the script.
This commit is contained in:
@@ -22,6 +22,21 @@ log() { printf '\033[1;34m==>\033[0m %s\n' "$*" >&2; }
|
||||
info() { printf ' \033[0;37m%s\033[0m\n' "$*" >&2; }
|
||||
ok() { printf ' \033[0;32m✓\033[0m %s\n' "$*" >&2; }
|
||||
|
||||
# _strip_think — remove reasoning tags from stdin
|
||||
# Buffer all input, locate the LAST </think> line, emit only what follows.
|
||||
# This handles think blocks that themselves contain </think> fragments.
|
||||
_strip_think() {
|
||||
awk '{
|
||||
lines[NR] = $0
|
||||
print $0 > "/dev/stderr"
|
||||
if (/^<\/think>/) last_end = NR
|
||||
}
|
||||
END {
|
||||
start = (last_end ? last_end + 1 : 1)
|
||||
for (i = start; i <= NR; i++) print lines[i]
|
||||
}'
|
||||
}
|
||||
|
||||
# _readable_diff <file>
|
||||
# Returns a human-readable diff for <file>.
|
||||
# For pathological single-line formats (JSON, minified JS/CSS…), pretty-prints
|
||||
@@ -104,7 +119,7 @@ while IFS= read -r file; do
|
||||
n=$((n + 1))
|
||||
log "[$n/$file_count] Summarising $file …"
|
||||
|
||||
summary=$(printf '%s' "$diff" | aichat "In 2-3 lines, summarise what this diff changes in the file '$file'. Be concise and technical.")
|
||||
summary=$(printf '%s' "$diff" | aichat "In 2-3 lines, summarise what this diff changes in the file '$file'. Be concise and technical." | _strip_think)
|
||||
|
||||
# Print the summary indented to stderr
|
||||
while IFS= read -r line; do
|
||||
@@ -123,10 +138,10 @@ if [[ -z "$summaries" ]]; then
|
||||
fi
|
||||
|
||||
log "Generating commit message from $n summary/summaries …"
|
||||
result=$(printf '%s' "$summaries" | aichat "From these per-file summaries of a jj diff, write a single conventional commit message in English. First line: short imperative summary (max 72 chars). Then a blank line. Then a short paragraph with more detail if needed. Output only the commit message, nothing else.")
|
||||
result=$(printf '%s' "$summaries" | aichat "From these per-file summaries of a jj diff, write a single conventional commit message in English. First line: short imperative summary (max 72 chars). Then a blank line. Then a short paragraph with more detail if needed. Output only the commit message, nothing else." | _strip_think)
|
||||
|
||||
ok "Done"
|
||||
printf '\n' >&2
|
||||
|
||||
# Commit message goes to stdout
|
||||
printf '%s\n' "$result"
|
||||
# Commit message goes to stdout (strip leading blank lines so jj sees content)
|
||||
printf '%s\n' "$result" | sed '/./,$!d'
|
||||
|
||||
@@ -12,6 +12,7 @@ pub mod kmer;
|
||||
mod revcomp_lookup;
|
||||
/// Routable super-kmer: canonical sequence paired with its minimizer for scatter routing.
|
||||
pub mod routable;
|
||||
mod sequence;
|
||||
pub mod superkmer;
|
||||
|
||||
pub mod unitig;
|
||||
@@ -19,4 +20,5 @@ pub mod unitig;
|
||||
pub use annotations::Annotation;
|
||||
pub use kmer::CanonicalKmer;
|
||||
pub use routable::RoutableSuperKmer;
|
||||
pub use sequence::Sequence;
|
||||
pub use superkmer::SuperKmer;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
use crate::Annotation;
|
||||
|
||||
pub trait Sequence {
|
||||
fn sequence(&self) -> &[u8];
|
||||
fn canonical(&self) -> Self;
|
||||
fn sequence(&self) -> Box<[u8]>;
|
||||
fn canonical(&self) -> &Self;
|
||||
fn seq_hash(&self) -> u64;
|
||||
fn annotation(&self) -> Annotation;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
//! Compact 2-bit DNA super-kmer with in-place reverse complement and canonical form.
|
||||
use std::io::{self, Write};
|
||||
|
||||
use bitvec::prelude::*;
|
||||
use serde::Serialize;
|
||||
use xxhash_rust::xxh3::xxh3_64;
|
||||
|
||||
use crate::Sequence;
|
||||
use crate::encoding::{DEC4, encode_base};
|
||||
use crate::kmer::{CanonicalKmer, Kmer, KmerError};
|
||||
use crate::revcomp_lookup::REVCOMP4;
|
||||
use bitvec::prelude::*;
|
||||
use xxhash_rust::xxh3::xxh3_64;
|
||||
|
||||
// ── SuperKmerHeader ───────────────────────────────────────────────────────────
|
||||
|
||||
@@ -53,7 +54,7 @@ impl SuperKmerHeader {
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct CountAnnotation {
|
||||
struct SKAnnotation {
|
||||
seq_length: usize,
|
||||
kmer_size: usize,
|
||||
minimizer_size: usize,
|
||||
@@ -90,6 +91,22 @@ impl std::hash::Hash for SuperKmer {
|
||||
}
|
||||
}
|
||||
|
||||
impl Sequence for SuperKmer {
|
||||
fn sequence(&self) -> Box<[u8]> {
|
||||
self.seq.clone()
|
||||
}
|
||||
|
||||
fn canonical(&self) -> &Self {
|
||||
&self
|
||||
}
|
||||
|
||||
/// Returns the XXH3-64 hash of the packed sequence bytes.
|
||||
fn seq_hash(&self) -> u64 {
|
||||
xxh3_64(&self.seq)
|
||||
}
|
||||
|
||||
fn annotation(&self) -> Annotation {}
|
||||
}
|
||||
impl SuperKmer {
|
||||
/// `seql` is the raw stored byte: 1–255 for lengths 1–255, 0 for length 256.
|
||||
pub fn new(seql: u8, seq: Box<[u8]>) -> Self {
|
||||
@@ -315,11 +332,6 @@ impl SuperKmer {
|
||||
pub fn iter_canonical_kmers(&self, k: usize) -> impl Iterator<Item = CanonicalKmer> + '_ {
|
||||
self.iter_kmers(k).map(move |km| km.canonical(k))
|
||||
}
|
||||
|
||||
/// Returns the XXH3-64 hash of the packed sequence bytes.
|
||||
pub fn seq_hash(&self) -> u64 {
|
||||
xxh3_64(&self.seq)
|
||||
}
|
||||
}
|
||||
|
||||
struct SKKmerIter<'a> {
|
||||
|
||||
Reference in New Issue
Block a user