Lines 787-827javascript
788 const promptChanged = next.promptText !== current;
789 const agentsChanged = next.agentsText !== currentAgents;
790 const skillSwitchesChanged = JSON.stringify(runtime.skillSwitches) !== JSON.stringify(nextRuntime.skillSwitches);
791 const settingsChanged = runtime.writeAgents !== nextRuntime.writeAgents || runtime.writePreset !== nextRuntime.writePreset || runtime.injectAgentsPrompt !== nextRuntime.injectAgentsPrompt || runtime.injectPrompt !== nextRuntime.injectPrompt || skillSwitchesChanged || runtime.anchorFirstTurn !== nextRuntime.anchorFirstTurn || runtime.anchorText !== nextRuntime.anchorText ||
792 if (!needsInitialApply && !promptChanged && !agentsChanged && !settingsChanged) return;
793 needsInitialApply = false;
794 if (promptChanged) current = next.promptText;
795 if (agentsChanged) currentAgents = next.agentsText;
796 runtime.writeAgents = nextRuntime.writeAgents;
797 runtime.writePreset = nextRuntime.writePreset;
798 runtime.injectAgentsPrompt = nextRuntime.injectAgentsPrompt;
799 runtime.injectPrompt = nextRuntime.injectPrompt;
800 runtime.skillSwitches = nextRuntime.skillSwitches;
801 runtime.anchorFirstTurn = nextRuntime.anchorFirstTurn;
802 runtime.anchorText = nextRuntime.anchorText;
803 runtime.anchorCustom = nextRuntime.anchorCustom;
804 runtime.subagentFlash = nextRuntime.subagentFlash;
805 skillSwitches = runtime.skillSwitches;
806 if (skillSwitchesChanged) invalidateSkills?.();
807 let residentAgentsWritten = false;
808 if (runtime.writeAgents) {
809 residentAgentsWritten = writeAgents(currentAgents, config.residentAgentsPath);
810 if (!residentAgentsWritten) warn(ctx, `prompt-tool: failed to write resident rules to ${config.residentAgentsPath}`);
812 residentAgentsWritten = removeResidentAgentsBlock(config.residentAgentsPath);
813 if (!residentAgentsWritten) warn(ctx, `prompt-tool: failed to remove resident rules block from ${config.residentAgentsPath}`);
815 if (runtime.writePreset) writePreset(runtime.injectPrompt && current.length > 0 ? current : "", {
816 anchorFirstTurn: runtime.anchorFirstTurn,
817 anchorText: runtime.anchorText,
818 anchorCustom: runtime.anchorCustom,
819 injectPrompt: runtime.injectPrompt,
820 subagentFlash: runtime.subagentFlash,
821 subagentFlashProvider: config.subagentFlashProvider,
822 subagentFlashModel: config.subagentFlashModel,
823 customBashPath: config.customBashPath,
824 agentsInstructionText: runtime.injectAgentsPrompt && currentAgents.length > 0 ? currentAgents : void 0,
825 presetDir: config.presetDir,
826 presetOrder: config.presetOrder