fix: drop the auto_thread marker when a thread is rewritten (#29)
Editorial rewrites went through UpdateThread, which touched title, motivation, priority and tags but never provenance. isAutoThreaded keys off the auto_thread provenance marker (or an 'Auto-detected' motivation prefix), so every polished thread kept reporting as a draft with no way out of the queue. A rewritten title or motivation now clears the marker and records groomed=true, keeping the cluster/score/sources that provenance also carries. Tag-only edits deliberately do not count as an editorial pass.
This commit is contained in:
+36
-3
@@ -4,6 +4,7 @@ import (
|
||||
"crypto/rand"
|
||||
"database/sql"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"os"
|
||||
@@ -1731,6 +1732,10 @@ func (k *KnoxDB) CloseThread(id int64) error {
|
||||
// UpdateThread rewrites the editorial fields of a thread (used by the LLM
|
||||
// draft/polish pass to replace auto-generated titles/motivations). Empty
|
||||
// strings leave the corresponding field unchanged; omitting them all is a no-op.
|
||||
//
|
||||
// A rewritten title or motivation counts as editorial: the auto_thread
|
||||
// provenance marker is dropped so the thread stops reporting as a draft. The
|
||||
// rest of the provenance (cluster, score, sources) is kept.
|
||||
func (k *KnoxDB) UpdateThread(id int64, title, motivation, priority, tags string) (bool, error) {
|
||||
t, err := k.GetThread(id)
|
||||
if err != nil || t == nil {
|
||||
@@ -1748,17 +1753,45 @@ func (k *KnoxDB) UpdateThread(id int64, title, motivation, priority, tags string
|
||||
if tags == "" {
|
||||
tags = t.Tags
|
||||
}
|
||||
changed := title != t.Title || motivation != t.Motivation || priority != t.Priority || tags != t.Tags
|
||||
provenance := t.Provenance
|
||||
if title != t.Title || motivation != t.Motivation {
|
||||
provenance = clearAutoThreadMarker(provenance)
|
||||
}
|
||||
changed := title != t.Title || motivation != t.Motivation || priority != t.Priority ||
|
||||
tags != t.Tags || provenance != t.Provenance
|
||||
if !changed {
|
||||
return false, nil
|
||||
}
|
||||
_, err = k.db.Exec(
|
||||
`UPDATE threads SET title=?, motivation=?, priority=?, tags=?, updated_at=datetime('now') WHERE id=?`,
|
||||
title, motivation, priority, tags, id,
|
||||
`UPDATE threads SET title=?, motivation=?, priority=?, tags=?, provenance=?, updated_at=datetime('now') WHERE id=?`,
|
||||
title, motivation, priority, tags, provenance, id,
|
||||
)
|
||||
return true, err
|
||||
}
|
||||
|
||||
// clearAutoThreadMarker removes the auto_thread trigger from a thread's
|
||||
// provenance JSON, recording that a human or agent has since rewritten it.
|
||||
// Unparseable or unrelated provenance is returned unchanged.
|
||||
func clearAutoThreadMarker(provenance string) string {
|
||||
if !strings.Contains(provenance, "auto_thread") {
|
||||
return provenance
|
||||
}
|
||||
var meta map[string]any
|
||||
if err := json.Unmarshal([]byte(provenance), &meta); err != nil {
|
||||
return provenance
|
||||
}
|
||||
if trigger, _ := meta["trigger"].(string); trigger != "auto_thread" {
|
||||
return provenance
|
||||
}
|
||||
delete(meta, "trigger")
|
||||
meta["groomed"] = true
|
||||
out, err := json.Marshal(meta)
|
||||
if err != nil {
|
||||
return provenance
|
||||
}
|
||||
return string(out)
|
||||
}
|
||||
|
||||
func (k *KnoxDB) LinkObservationToThread(threadID, observationID int64, relevance string) error {
|
||||
tx, err := k.db.Begin()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user