返回 DeepSeek-Reasonix
trajmode.go
根目录 / cmd / e2ebench / trajmode.go
1 package main
2
3 import (
4 "encoding/json"
5 "fmt"
6 "os"
7 "path/filepath"
8 "sort"
9 "strings"
10 )
11
12 // runTrajMode re-digests already-recorded trajectory files, so digest changes
13 // can be evaluated against past runs without re-spending provider tokens.
14 // Wall-clock startup is unknown offline, so the decomposition omits it.
15 func runTrajMode(dir string) (string, error) {
16 paths, err := filepath.Glob(filepath.Join(dir, "*.trajectory.jsonl"))
17 if err != nil {
18 return "", err
19 }
20 if len(paths) == 0 {
21 return "", fmt.Errorf("no *.trajectory.jsonl files under %s", dir)
22 }
23 sort.Strings(paths)
24
25 var b strings.Builder
26 var results []result
27 for _, p := range paths {
28 s, err := summarizeTrajectory(p)
29 if err != nil {
30 return "", fmt.Errorf("%s: %w", p, err)
31 }
32 id := strings.TrimSuffix(filepath.Base(p), ".trajectory.jsonl")
33 results = append(results, result{task: task{ID: id}, Trajectory: s})
34 enc, err := json.MarshalIndent(s, "", " ")
35 if err != nil {
36 return "", err
37 }
38 fmt.Fprintf(&b, "### `%s`\n\n```json\n%s\n```\n\n", id, enc)
39 }
40 return "## Trajectory digest\n\n" + renderTimeAttribution(results) + renderToolSurface(results) + renderAnchorSafety(results) + renderOutcomeProgress(results) + renderCognition(results) + renderDelegationAdmission(results) + renderMechanismLedger(results) + b.String(), nil
41 }
42
43 func emitTrajMode(dir, outMD string) {
44 report, err := runTrajMode(dir)
45 if err != nil {
46 fmt.Fprintln(os.Stderr, "traj mode:", err)
47 os.Exit(1)
48 }
49 emit(report, outMD, "")
50 }
51
51 lines GO