The backend no longer broadcasts topic lifecycle events to Fabric. The
new model (per design discussion 2026-05-23 evening):
- Proposing agent posts a single recruitment fabric-send-message
immediately after creating a topic (carries topic_id + signup
window + debate window + title).
- Downstream agents that decide to participate book a HF on_call
slot covering the debate window via `hf calendar schedule on_call
<time> <duration> --job DEBATE-<topic_id>`.
- HF wakes the agent naturally at slot start; the wake payload
carries event_data with the DEBATE-<topic_id> code so the agent
knows why it was woken.
- The backend stays a pure data + state-machine service and doesn't
know about Fabric.
Code removed:
- internal/fabric/announce.go (entire file + empty dir)
- ticker.go: broadcastLifecycle + broadcastAnnouncement + topicTarget
helpers; announcer field on Ticker; announce field/arg on NewTicker
- models/topic.go: AnnounceGuildBaseURL + AnnounceChannelID fields
- store/topic_store.go: same fields on CreateTopicInput + INSERT
- handlers/topics.go: same fields on createTopicBody + validation +
parameter passing to store
- handlers/verdict.go: announcer field + lifecycle broadcast on
verdict submit
- config/config.go: FabricSystemAPIKey field + DIALECTIC_FABRIC_SYSTEM_API_KEY
env read
- main.go + routes.go: announcer wiring
Database:
- migrations/003_drop_topic_announce_target.sql drops the two columns
added by migration 002. Counterpart commit on the deployment side
needs DIALECTIC_FABRIC_SYSTEM_API_KEY env removed from
docker-compose.yml; harmless if left as the backend no longer
reads it.
Pairs with:
- Dialectic.OpenclawPlugin: rip announce_* params from
dialectic_propose_topic (next commit)
- Fabric.Backend.Center: rip serviceEndpoint field + cli
- Fabric.Backend.Guild: rip system-key bypass on ApiKeyGuard and
announce-only-system limit on messaging.controller
- ClawSkills: rewrite participate-debate + analyze-intel step 4 +
delete rotate-fabric-system-key workflow
121 lines
3.3 KiB
Go
121 lines
3.3 KiB
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jmoiron/sqlx"
|
|
|
|
"git.hangman-lab.top/hzhang/Dialectic.Backend/internal/models"
|
|
)
|
|
|
|
var ErrNotFound = errors.New("not found")
|
|
|
|
type TopicStore struct {
|
|
db *sqlx.DB
|
|
}
|
|
|
|
func NewTopicStore(db *sqlx.DB) *TopicStore { return &TopicStore{db: db} }
|
|
|
|
type CreateTopicInput struct {
|
|
Title string
|
|
Summary string
|
|
Visibility models.Visibility
|
|
VerdictSchemaID string
|
|
SignupOpenAt time.Time
|
|
SignupCloseAt time.Time
|
|
DebateStartAt time.Time
|
|
DebateEndAt time.Time
|
|
CreatorUserID string
|
|
}
|
|
|
|
func (s *TopicStore) Create(ctx context.Context, in CreateTopicInput) (*models.Topic, error) {
|
|
id := uuid.NewString()
|
|
_, err := s.db.ExecContext(ctx, `
|
|
INSERT INTO topics (id, title, summary, visibility, verdict_schema_id,
|
|
signup_open_at, signup_close_at, debate_start_at, debate_end_at,
|
|
creator_user_id)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
id, in.Title, in.Summary, in.Visibility, in.VerdictSchemaID,
|
|
in.SignupOpenAt, in.SignupCloseAt, in.DebateStartAt, in.DebateEndAt,
|
|
in.CreatorUserID)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("insert topic: %w", err)
|
|
}
|
|
return s.GetByID(ctx, id)
|
|
}
|
|
|
|
func (s *TopicStore) GetByID(ctx context.Context, id string) (*models.Topic, error) {
|
|
var t models.Topic
|
|
err := s.db.GetContext(ctx, &t, `SELECT * FROM topics WHERE id = ?`, id)
|
|
if errors.Is(err, sql.ErrNoRows) {
|
|
return nil, ErrNotFound
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &t, nil
|
|
}
|
|
|
|
type ListFilter struct {
|
|
Status string // empty = all
|
|
Visibility string // empty = all
|
|
Limit int // 0 = default 50
|
|
Offset int
|
|
}
|
|
|
|
func (s *TopicStore) List(ctx context.Context, f ListFilter) ([]models.Topic, error) {
|
|
if f.Limit <= 0 || f.Limit > 200 {
|
|
f.Limit = 50
|
|
}
|
|
q := "SELECT * FROM topics"
|
|
args := []any{}
|
|
var clauses []string
|
|
if f.Status != "" {
|
|
clauses = append(clauses, "status = ?")
|
|
args = append(args, f.Status)
|
|
}
|
|
if f.Visibility != "" {
|
|
clauses = append(clauses, "visibility = ?")
|
|
args = append(args, f.Visibility)
|
|
}
|
|
if len(clauses) > 0 {
|
|
q += " WHERE " + strings.Join(clauses, " AND ")
|
|
}
|
|
q += " ORDER BY created_at DESC LIMIT ? OFFSET ?"
|
|
args = append(args, f.Limit, f.Offset)
|
|
|
|
var rows []models.Topic
|
|
if err := s.db.SelectContext(ctx, &rows, q, args...); err != nil {
|
|
return nil, err
|
|
}
|
|
return rows, nil
|
|
}
|
|
|
|
// SetStatus is a low-level status update. Most transitions go through
|
|
// the orchestrator's tx-wrapped paths; this is for the verdict handler
|
|
// (debating → completed on successful judge submission) and admin tools.
|
|
func (s *TopicStore) SetStatus(ctx context.Context, id string, status models.TopicStatus) (*models.Topic, error) {
|
|
if _, err := s.db.ExecContext(ctx,
|
|
`UPDATE topics SET status = ? WHERE id = ?`, status, id); err != nil {
|
|
return nil, err
|
|
}
|
|
return s.GetByID(ctx, id)
|
|
}
|
|
|
|
// SetVisibility flips public/private; records who/when. Returns updated row.
|
|
func (s *TopicStore) SetVisibility(ctx context.Context, id string, v models.Visibility, byUserID string) (*models.Topic, error) {
|
|
_, err := s.db.ExecContext(ctx, `
|
|
UPDATE topics SET visibility = ?, visibility_changed_by = ?, visibility_changed_at = CURRENT_TIMESTAMP
|
|
WHERE id = ?`, v, byUserID, id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return s.GetByID(ctx, id)
|
|
}
|