| 1 | package control |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | |
| 6 | "reasonix/internal/agent" |
| 7 | "reasonix/internal/sessioncontext" |
| 8 | "reasonix/internal/skill" |
| 9 | ) |
| 10 | |
| 11 | // withTurnContext attaches current role-specific snapshots to a host turn. |
| 12 | // Synthetic turns receive bootstrap-only context: they may repair an upgraded |
| 13 | // legacy session with no snapshot, but never advertise a mid-session update. |
| 14 | func (c *Controller) withTurnContext(ctx context.Context, realUserTurn bool) context.Context { |
| 15 | if c == nil { |
| 16 | return ctx |
| 17 | } |
| 18 | base := c.sessionContextStatic |
| 19 | if mem := c.memory.current(); mem != nil { |
| 20 | base.BackgroundMemory = mem.BackgroundDataBlock() |
| 21 | } |
| 22 | |
| 23 | executorSections := base |
| 24 | plannerSections := base |
| 25 | if !c.disableImplicitSkillInvocation { |
| 26 | sk := c.skills.list() |
| 27 | executorSections.SkillsCatalog = skill.CatalogBlock(sk) |
| 28 | plannerSections.SkillsCatalog = skill.ReadOnlyCatalogBlock(sk) |
| 29 | } |
| 30 | bundle := agent.TurnContextBundle{ |
| 31 | Executor: sessioncontext.Build(executorSections), |
| 32 | Planner: sessioncontext.Build(plannerSections), |
| 33 | BootstrapOnly: !realUserTurn, |
| 34 | } |
| 35 | return agent.WithTurnContextBundle(ctx, bundle) |
| 36 | } |
| 37 |