返回 DeepSeek-Reasonix
projection_bind.go
根目录 / internal / control / projection_bind.go
1 package control
2
3 import (
4 "fmt"
5 "log/slog"
6 "time"
7
8 "reasonix/internal/agent"
9 "reasonix/internal/event"
10 )
11
12 // bindExecutorProjection rebinds the agent's projection sidecar to path.
13 // loadSidecar=true loads an existing sidecar (resume/switch); false clears
14 // in-memory projection without deleting another session's .context.json.
15 func (c *Controller) bindExecutorProjection(path string, loadSidecar bool) {
16 if c == nil || c.executor == nil {
17 return
18 }
19 if c.sessionEngineEnabled() {
20 return
21 }
22 c.executor.BindSessionPath(path, loadSidecar)
23 }
24
25 // maybeColdResumePrune records warm/cold/unknown only; it never rewrites history.
26 func (c *Controller) maybeColdResumePrune(path string) {
27 if c.executor == nil || path == "" {
28 return
29 }
30 // Sidecar path is rebound in Resume; only refresh cache state here.
31 m, ok, err := agent.LoadBranchMeta(path)
32 if err != nil || !ok || m.UpdatedAt.IsZero() {
33 c.executor.SetCacheState(agent.CacheStateUnknown)
34 slog.Info("controller: resume cache state", "path", path, "cache_state", agent.CacheStateUnknown)
35 return
36 }
37 last := m.UpdatedAt
38 state := agent.CacheStateWarm
39 if time.Since(last) >= c.cacheColdAfter() {
40 state = agent.CacheStateCold
41 }
42 c.executor.SetCacheState(state)
43 slog.Info("controller: resume cache state", "path", path, "cache_state", state, "idle", time.Since(last).Round(time.Minute).String())
44 if c.disableColdResumePrune || state != agent.CacheStateCold {
45 return
46 }
47 c.sink.Emit(event.Event{Kind: event.Notice, Level: event.LevelInfo, Text: fmt.Sprintf(
48 "resumed after %s idle (provider cache likely expired) — full history kept; compaction deferred until context pressure",
49 time.Since(last).Round(time.Minute))})
50 }
51
51 lines GO