| 1 | package boot |
| 2 | |
| 3 | import ( |
| 4 | "reasonix/internal/command" |
| 5 | "reasonix/internal/extension" |
| 6 | "reasonix/internal/hook" |
| 7 | "reasonix/internal/skill" |
| 8 | "reasonix/internal/tool" |
| 9 | ) |
| 10 | |
| 11 | // ReusedAssembly holds rediscovery-free inputs for narrow/no-op rebuilds. |
| 12 | // Populated on successful BuildRuntime so the next RebuildFrom can skip |
| 13 | // skill/command/hook rediscovery and snapshot re-freeze when the plan allows. |
| 14 | type ReusedAssembly struct { |
| 15 | SystemPrompt string |
| 16 | Skills []skill.Skill |
| 17 | Commands []command.Command |
| 18 | Hooks []hook.ResolvedHook |
| 19 | Registry *tool.Registry |
| 20 | ImplicitSkillInvocation bool |
| 21 | } |
| 22 | |
| 23 | // shouldReuseDiscovery reports whether rediscovery of skills/commands/hooks |
| 24 | // can be skipped for this rebuild plan. Provider-only and MCP-only rebuilds |
| 25 | // do not change skill/command/hook discovery either — only the live backend. |
| 26 | func shouldReuseDiscovery(plan *extension.RuntimePlan) bool { |
| 27 | if plan == nil { |
| 28 | return false |
| 29 | } |
| 30 | switch plan.Kind { |
| 31 | case extension.SubgraphNone, |
| 32 | extension.SubgraphInterceptorOnly, |
| 33 | extension.SubgraphUIOnly, |
| 34 | extension.SubgraphProviderOnly, |
| 35 | extension.SubgraphMCPOnly: |
| 36 | return true |
| 37 | default: |
| 38 | return false |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | // shouldReuseSnapshot reports whether the previous RuntimeSnapshot body can be |
| 43 | // re-published with a new generation (provider-visible prefix unchanged). |
| 44 | func shouldReuseSnapshot(plan *extension.RuntimePlan) bool { |
| 45 | if plan == nil { |
| 46 | return false |
| 47 | } |
| 48 | return plan.IsNoOp() || !plan.MayChangePrefix() |
| 49 | } |
| 50 | |
| 51 | // shouldSkipPromptStrategy is true when system_prompt.build must not re-run. |
| 52 | func shouldSkipPromptStrategy(plan *extension.RuntimePlan) bool { |
| 53 | return shouldReuseSnapshot(plan) |
| 54 | } |
| 55 |