refactor(agent): gadfly round 2 — shared leadingMarkers, explicit mode, comment altitude
All tidiness, no behavior change: the leading-marker class is one shared constant for citationLabelRe and summaryCloserRe (hand-copying it is how '+' went missing the first time); the deliberate 'all' duplication across summaryCopulas/summaryArticle is now stated at both sites; the weak-final switch case assigns modeBackRef explicitly; test comments state the constraint they guard instead of which reviewer asked for them. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
+14
-4
@@ -52,7 +52,7 @@ func finalOutput(msgs []llm.Message, terminal string) string {
|
||||
case isCitationsOnly(terminal):
|
||||
mode = modeCitations
|
||||
case isWeakFinal(terminal):
|
||||
// modeBackRef
|
||||
mode = modeBackRef
|
||||
case isSummaryCloser(terminal):
|
||||
mode = modeSummary
|
||||
default:
|
||||
@@ -128,15 +128,17 @@ var backRefRe = regexp.MustCompile(`(?i)(already answered|see above|as (i )?(sai
|
||||
// behavior (fail closed). Assembled from named fragments so the alternations
|
||||
// stay legible and extendable.
|
||||
const (
|
||||
summaryLead = `[\s>#*_+-]*` // leading markdown/list markers, as in citationLabelRe
|
||||
summaryPreface = `((done|all set|ok(ay)?)[\s,.!:—-]+)?` // optional "Done —" style opener
|
||||
summaryNouns = `(citations?|sources?|references?|claims?)`
|
||||
// "all" appears here AND in summaryArticle on purpose: as a quantifier
|
||||
// between noun and verb ("Citations all logged.") and as a determiner
|
||||
// before the noun ("All claims cited.", "Logged all the citations.").
|
||||
summaryCopulas = `((are|were|have\s+been|all)\s+)*`
|
||||
summaryVerbs = `(logged|recorded|cited|saved|noted|captured|filed)`
|
||||
summaryArticle = `((all|the)\s+)*` // star, not ?: "Logged all the citations."
|
||||
)
|
||||
|
||||
var summaryCloserRe = regexp.MustCompile(`(?i)^` + summaryLead + summaryPreface +
|
||||
var summaryCloserRe = regexp.MustCompile(`(?i)^` + leadingMarkers + summaryPreface +
|
||||
`(` + summaryArticle + summaryNouns + `\s+` + summaryCopulas + summaryVerbs +
|
||||
`|logged\s+` + summaryArticle + summaryNouns + `)[.!]`)
|
||||
|
||||
@@ -153,7 +155,15 @@ var preambleRe = regexp.MustCompile(`(?i)^(let me|let'?s|i'?ll|i will|first[, ]|
|
||||
// the colon/dash separator. Anchored at ^ so a normal answer that merely
|
||||
// mentions "sources" mid-sentence, or ends with a "Sources:" section AFTER its
|
||||
// prose, is never matched.
|
||||
var citationLabelRe = regexp.MustCompile(`(?i)^[\s>#*_+-]*(sources?|references?|citations?|works cited|further reading)\b[\s*_]*[::\-—]`)
|
||||
var citationLabelRe = regexp.MustCompile(`(?i)^` + leadingMarkers +
|
||||
`(sources?|references?|citations?|works cited|further reading)\b[\s*_]*[::\-—]`)
|
||||
|
||||
// leadingMarkers tolerates markdown noise before a label: emphasis (*, _),
|
||||
// list (-, +, *), block-quote (>), and ATX-heading (#) markers, with their
|
||||
// whitespace. Shared by citationLabelRe and summaryCloserRe so the two
|
||||
// classifiers cannot drift apart (the first draft of the summary class
|
||||
// dropped '+' by hand-copying this set).
|
||||
const leadingMarkers = `[\s>#*_+-]*`
|
||||
|
||||
// linkRe matches a whole markdown link "[label](url)" or a bare URL. Used both
|
||||
// to require that a citations terminal carries at least one link and to strip
|
||||
|
||||
Reference in New Issue
Block a user