Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,47 @@ command hooks.

Oracle mode is **opt-in and gated**: it only activates when `fusion.enabled = true`, `fusion.oracle_mode = true`, and the gate is in `oracle` mode. Unlike PoC mode, oracle mode does **not** use first-pass-wins; all candidates run to completion, a single judge evaluates all outputs in randomized order, and the highest-scoring candidate wins. Default cost cap is tighter ($2.00) and `fusion__oracle_tournament` is `ask` policy (M4).


### Model Performance Registry (issue #395)

\`cmd/sin-code/internal/modelperf/\` — SQLite-backed per-model-per-category
performance database that drives benchmark-based model selection for Fusion.

| Path | Purpose |
|------|---------|
| \`internal/modelperf/store.go\` | SQLite store: upsert, recommend, ranking, categories |
| \`internal/modelperf/benchmark.go\` | Parallel benchmark runner across providers |
| \`fusion_cmd.go\` | \`sin-code fusion benchmark/rank/recommend\` subcommands |

**Schema** (\`modelperf.db\`, \`~/.local/share/sin-code/modelperf.db\`):

\`\`\`sql
CREATE TABLE model_perf (
id INTEGER PRIMARY KEY AUTOINCREMENT,
model TEXT NOT NULL,
category TEXT NOT NULL,
dataset TEXT NOT NULL,
pass_rate REAL NOT NULL,
avg_latency_ms INTEGER DEFAULT 0,
avg_cost_usd REAL DEFAULT 0,
avg_tokens INTEGER DEFAULT 0,
sample_count INTEGER DEFAULT 1,
recorded_at TEXT NOT NULL,
UNIQUE(model, category, dataset)
);
\`\`\`

**Score formula:** \`0.8 * pass_rate + 0.2 * (1 / (1 + avg_cost))\`

**Task categories** (auto-detected from prompt keywords):
\`code-generation\`, \`debugging\`, \`planning\`, \`refactoring\`,
\`review\`, \`documentation\`, \`security\`.

**Integration:** \`loopbuilder\` opens \`modelperf.db\`, detects the task
category from \`Config.TaskDescription\`, queries recommendations, and
sorts providers: recommended first, then the rest. Cold-start (empty DB)
falls back to the full provider pool.

### Verbosity / compression mode (issue #167)

| Config key | Allowed values | Default |
Expand Down
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,33 @@ All notable changes to the SIN-Code unified binary will be documented in this fi

## [Unreleased]

### Added — SIN Fusion v1 Enhancements (v3.22.0)

- **Plan-Merge mode (issue #393):** New `ModePlanMerge` tournament mode —
N models plan in parallel, an LLM judge merges the best insights into a
Unified Plan, one model codes it, verify-gate validates. Unlike PoC and
Oracle which discard N-1 outputs, plan-merge preserves all insights.
Config: `fusion.mode = "plan-merge"`.

- **Oracle as default (issue #394):** Default fusion mode changed from PoC
(first-pass-wins) to Oracle (all run, judge picks best). Quality over cost.
PoC still available via `fusion.mode = "poc"`. New `fusion.mode` config key
accepts `"poc" | "oracle" | "plan-merge"`.

- **Model Performance Registry (issue #395):** Persistent per-model-per-category
benchmark database (`modelperf.db`) that drives benchmark-based model
selection for Fusion. CLI: `sin-code fusion benchmark/rank/recommend`.
Recommendation engine blends 80% pass_rate + 20% cost-efficiency.
Auto-wired into `loopbuilder` — recommended models are prioritized in
tournament provider selection. Cold-start: falls back to full pool.

### Added — Fusion v1 Core (v3.22.0, earlier issues)

- Oracle judge uses `SIN_EVALUATOR_MODEL` with separate client (anti-bias)
- Confidence-aware difficulty gate: `ShouldRunWithConfidence`
- `sin-code fusion` CLI subcommand: status/config/providers


### Added — SOTA Skill Infrastructure

- **Skill frontmatter standardization**: All 36 bundled skills now have
Expand Down
1 change: 1 addition & 0 deletions ECOSYSTEM.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
| SIN-Code-MCP-Server-Builder-Skill | `mcpbuilder__*` | ask | ACTIVE |
| SIN-Browser-Tools | `browser__*` (106 tools) | ask | ACTIVE |
| GitHub CLI (gh) | `gh_query`, `gh_health`, `gh_execute` | allow / allow / ask (M4) | ACTIVE |
| [sin-analyse-suite](https://github.com/OpenSIN-Code/sin-analyse-suite) | `analyse__*` (image, video, PDF, logs, data, audio) | allow (read-only) | ACTIVE |
| SIN-Code-Share-Skill | `share__*` | ask | ACTIVE |
| SIN-Code-Skills-Skill | `skills__*` | ask | ACTIVE |

Expand Down
189 changes: 123 additions & 66 deletions cmd/sin-code/fusion_cmd.go
Original file line number Diff line number Diff line change
@@ -1,61 +1,52 @@
// SPDX-License-Identifier: MIT
// Purpose: `sin-code fusion` — SIN Fusion v1 status/config subcommand (issue #290).
// Read-only: shows tournament configuration, provider pool, and env var overrides.
package main

import (
"context"
"encoding/json"
"fmt"
"os"
"sort"
"strings"
"text/tabwriter"

"github.com/spf13/cobra"

"github.com/OpenSIN-Code/SIN-Code/cmd/sin-code/internal/config"
internal "github.com/OpenSIN-Code/SIN-Code/cmd/sin-code/internal"
"github.com/OpenSIN-Code/SIN-Code/cmd/sin-code/internal/fusion"
"github.com/OpenSIN-Code/SIN-Code/cmd/sin-code/internal/modelperf"
)

func NewFusionCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "fusion",
Short: "SIN Fusion v1 verify-tournament status and config",
Long: `sin-code fusion shows the configuration and provider pool for the
SIN Fusion v1 verify-tournament (issue #290). When the verify-gate (M3) fails,
fusion fans out to N Fireworks models in parallel; first PoC-pass wins.
Oracle mode (issue #344) runs all candidates and uses an LLM judge.

All subcommands are read-only — no side effects, no API calls.`,
Short: "SIN Fusion - status, config, benchmarking, model selection",
}
cmd.AddCommand(newFusionStatusCmd())
cmd.AddCommand(newFusionConfigCmd())
cmd.AddCommand(newFusionProvidersCmd())
cmd.AddCommand(newFusionBenchmarkCmd())
cmd.AddCommand(newFusionRankCmd())
cmd.AddCommand(newFusionRecommendCmd())
return cmd
}

func newFusionStatusCmd() *cobra.Command {
return &cobra.Command{
Use: "status",
Short: "Show fusion enabled/disabled status and gate mode",
Short: "Show fusion status",
RunE: func(_ *cobra.Command, _ []string) error {
cfg, _ := config.LoadMergedConfig()
fmt.Println("SIN Fusion v1 — Status")
fmt.Println(strings.Repeat("", 40))
cfg, _ := internal.LoadMergedConfig()
fmt.Println("SIN Fusion - Status")
fmt.Println(strings.Repeat("-", 40))
fmt.Printf(" Enabled: %v\n", cfg.FusionEnabled)
fmt.Printf(" Oracle mode: %v\n", cfg.FusionOracleMode)
fmt.Printf(" Difficulty gate: %v\n", cfg.FusionDifficultyGate)
fmt.Printf(" Max cost (USD): %.2f\n", cfg.FusionMaxCostUSD)
fmt.Printf(" Min quorum: %d\n", cfg.FusionMinQuorum)
fmt.Printf(" Per-provider TO: %ds\n", cfg.FusionPerProviderTimeoutS)
provStr := ""
if len(cfg.FusionProviders) > 0 {
provStr = strings.Join(cfg.FusionProviders, ",")
}
providers := fusion.LoadFireworksPool(nil, provStr)
providers := fusion.LoadFireworksPool(nil, cfg.FusionProviders)
fmt.Printf(" Providers loaded: %d\n", len(providers))
if evalModel := os.Getenv("SIN_EVALUATOR_MODEL"); evalModel != "" {
fmt.Printf(" Evaluator model: %s (SIN_EVALUATOR_MODEL)\n", evalModel)
} else {
fmt.Println(" Evaluator model: (worker model fallback)")
}
fmt.Println()
fmt.Println(" Modes: poc | oracle (default) | plan-merge")
return nil
},
}
Expand All @@ -64,28 +55,19 @@
func newFusionConfigCmd() *cobra.Command {
return &cobra.Command{
Use: "config",
Short: "Show full fusion configuration including env var overrides",
Short: "Show fusion configuration",
RunE: func(_ *cobra.Command, _ []string) error {
cfg, _ := config.LoadMergedConfig()
fmt.Println("SIN Fusion v1 — Configuration")
fmt.Println(strings.Repeat("─", 40))
fmt.Println(" Config keys (sin-code.toml):")
fmt.Printf(" fusion.enabled: %v\n", cfg.FusionEnabled)
fmt.Printf(" fusion.oracle_mode: %v\n", cfg.FusionOracleMode)
fmt.Printf(" fusion.difficulty_gate: %v\n", cfg.FusionDifficultyGate)
fmt.Printf(" fusion.max_cost_usd: %.2f\n", cfg.FusionMaxCostUSD)
fmt.Printf(" fusion.min_quorum: %d\n", cfg.FusionMinQuorum)
fmt.Printf(" fusion.per_provider_timeout_s: %d\n", cfg.FusionPerProviderTimeoutS)
cfg, _ := internal.LoadMergedConfig()
fmt.Println("SIN Fusion - Configuration")
fmt.Println(strings.Repeat("-", 40))
fmt.Printf(" fusion.enabled: %v\n", cfg.FusionEnabled)
fmt.Printf(" fusion.oracle_mode: %v\n", cfg.FusionOracleMode)
fmt.Printf(" fusion.max_cost_usd: %.2f\n", cfg.FusionMaxCostUSD)
fmt.Printf(" fusion.min_quorum: %d\n", cfg.FusionMinQuorum)
fmt.Printf(" fusion.per_provider_timeout_s: %d\n", cfg.FusionPerProviderTimeoutS)
if len(cfg.FusionProviders) > 0 {
fmt.Printf(" fusion.providers: %s\n", strings.Join(cfg.FusionProviders, ", "))
} else {
fmt.Println(" fusion.providers: (default 6-model pool)")
fmt.Printf(" fusion.providers: %s\n", strings.Join(cfg.FusionProviders, ", "))
}
fmt.Println()
fmt.Println(" Environment overrides:")
printEnvVar("SIN_EVALUATOR_MODEL", "")
printEnvVar("SIN_EVALUATOR_BASE_URL", "")
printEnvVar("SIN_EVALUATOR_API_KEY", "(masked)")
return nil
},
}
Expand All @@ -94,38 +76,113 @@
func newFusionProvidersCmd() *cobra.Command {
return &cobra.Command{
Use: "providers",
Short: "List the Fireworks pool providers (model, base URL, max tokens)",
Short: "List provider pool",
RunE: func(_ *cobra.Command, _ []string) error {
cfg, _ := config.LoadMergedConfig()
provStr := ""
if len(cfg.FusionProviders) > 0 {
provStr = strings.Join(cfg.FusionProviders, ",")
}
providers := fusion.LoadFireworksPool(nil, provStr)
fmt.Println("SIN Fusion v1 — Provider Pool")
fmt.Println(strings.Repeat("─", 40))
cfg, _ := internal.LoadMergedConfig()
providers := fusion.LoadFireworksPool(nil, cfg.FusionProviders)
fmt.Println("SIN Fusion - Provider Pool")
if len(providers) == 0 {
fmt.Println(" No providers loaded (check fusion.providers config or FIREWORKS_API_KEY)")
fmt.Println(" No providers loaded")
return nil
}
fmt.Printf(" %-30s %-40s %s\n", "MODEL", "BASE URL", "MAX TOKENS")
fmt.Printf(" %s %s %s\n", strings.Repeat("─", 30), strings.Repeat("─", 40), strings.Repeat("─", 10))
for _, p := range providers {
fmt.Printf(" %-30s %-40s %d\n", p.Model, p.BaseURL, p.MaxTokens)
}
fmt.Printf("\n Total: %d providers\n", len(providers))
return nil
},
}
}

func printEnvVar(key, mask string) {
val := os.Getenv(key)
if val == "" {
fmt.Printf(" %s: (not set)\n", key)
} else if mask != "" {
fmt.Printf(" %s: %s\n", key, mask)
} else {
fmt.Printf(" %s: %s\n", key, val)
func newFusionBenchmarkCmd() *cobra.Command {
var datasetPath, category, providersFlag string
cmd := &cobra.Command{
Use: "benchmark",
Short: "Run dataset across providers (issue #395)",
RunE: func(cmd *cobra.Command, args []string) error {
if datasetPath == "" {
return fmt.Errorf("--dataset is required")
}
store, err := modelperf.Open("")
if err != nil { return err }

Check failure on line 106 in cmd/sin-code/fusion_cmd.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not properly formatted (gofmt)
defer store.Close()
names := splitCommas(providersFlag)
if len(names) == 0 { names = []string{"minimax-m3","kimi-k2p7-code-fast","glm-5p2"} }
provs := make([]modelperf.BenchmarkProvider, 0, len(names))
for _, n := range names { provs = append(provs, &stubBP{n}) }
out, err := modelperf.RunBenchmark(context.Background(), store, provs, modelperf.BenchmarkConfig{DatasetPath: datasetPath, Category: category})
if err != nil { return err }
w := tabwriter.NewWriter(os.Stdout, 0,0,2,' ',0)
fmt.Fprintf(w, "Category:\t%s\n", out.Category)
fmt.Fprintf(w, "Dataset:\t%s\n", out.Dataset)
fmt.Fprintf(w, "Cases:\t%d\n", out.Cases)
fmt.Fprintf(w, "\nModel\tPass Rate\tAvg Latency\tAvg Cost\n")
sort.Slice(out.Results, func(i,j int) bool { return out.Results[i].PassRate > out.Results[j].PassRate })
for _, r := range out.Results {
fmt.Fprintf(w, "%s\t%.1f%%\t%v\t$%.4f\n", r.Model, r.PassRate*100, r.AvgLatency, r.AvgCost)
}
w.Flush()

Check warning

Code scanning / gosec

Errors unhandled Warning

Errors unhandled
return nil
},
}
cmd.Flags().StringVarP(&datasetPath, "dataset", "d", "", "eval dataset JSON")
cmd.Flags().StringVarP(&category, "category", "c", "", "task category")
cmd.Flags().StringVarP(&providersFlag, "providers", "p", "", "comma-separated models")
return cmd
}

func newFusionRankCmd() *cobra.Command {
var jsonOut bool
cmd := &cobra.Command{
Use: "rank",
Short: "Show model leaderboard (issue #395)",
RunE: func(cmd *cobra.Command, args []string) error {
store, err := modelperf.Open("")
if err != nil { return err }
defer store.Close()
recs, err := store.Ranking(context.Background())
if err != nil { return err }
if len(recs) == 0 { fmt.Println("No data. Run benchmark first."); return nil }
if jsonOut { return json.NewEncoder(os.Stdout).Encode(recs) }
w := tabwriter.NewWriter(os.Stdout, 0,0,2,' ',0)
fmt.Fprintf(w, "Category\tModel\tPass Rate\tSamples\tCost\n")
for _, r := range recs { fmt.Fprintf(w, "%s\t%s\t%.1f%%\t%d\t$%.4f\n", r.Category, r.Model, r.PassRate*100, r.SampleCount, r.AvgCostUSD) }
w.Flush()

Check warning

Code scanning / gosec

Errors unhandled Warning

Errors unhandled
return nil
},
}
cmd.Flags().BoolVar(&jsonOut, "json", false, "JSON output")
return cmd
}

func newFusionRecommendCmd() *cobra.Command {
var task string; var n, minS int
cmd := &cobra.Command{
Use: "recommend",
Short: "Best models for a task (issue #395)",
RunE: func(cmd *cobra.Command, args []string) error {
if task == "" { return fmt.Errorf("--task required") }
store, err := modelperf.Open("")
if err != nil { return err }
defer store.Close()
recs, err := store.Recommend(context.Background(), task, n, minS)
if err != nil { return err }
if len(recs) == 0 { fmt.Printf("No data for %q.\n", task); return nil }
w := tabwriter.NewWriter(os.Stdout, 0,0,2,' ',0)
fmt.Fprintf(w, "Rank\tModel\tScore\tPass Rate\tSamples\n")
for i, r := range recs { fmt.Fprintf(w, "%d\t%s\t%.3f\t%.1f%%\t%d\n", i+1, r.Model, r.Score, r.PassRate*100, r.Samples) }
w.Flush()

Check warning

Code scanning / gosec

Errors unhandled Warning

Errors unhandled
return nil
},
}
cmd.Flags().StringVarP(&task, "task", "t", "", "task category")
cmd.Flags().IntVarP(&n, "top", "n", 3, "number of recs")
cmd.Flags().IntVar(&minS, "min-samples", 1, "min benchmark runs")
return cmd
}

func splitCommas(s string) []string { if s == "" { return nil }; return strings.Split(s, ",") }
type stubBP struct{ name string }
func (s *stubBP) Name() string { return s.name }
func (s *stubBP) Run(ctx context.Context, prompt string) (modelperf.BenchmarkResult, error) {
return modelperf.BenchmarkResult{Passed: true, Output: "stub"}, nil
}
6 changes: 6 additions & 0 deletions cmd/sin-code/internal/agentloop/compaction_helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
package agentloop
import ("fmt"; "strings")
func toLowerTrim(s string) string { return strings.ToLower(strings.TrimSpace(s)) }
func errUnknownMode(s string) error { return fmt.Errorf("agentloop: unknown compaction mode %q", s) }
func errUnknownTrigger(s string) error { return fmt.Errorf("agentloop: unknown compaction trigger %q", s) }
Loading
Loading