MCPcopy Create free account
hub / github.com/Noumena-Network/code / contextModifier

Function contextModifier

src/tools/SkillTool/SkillTool.ts:776–840  ·  view source on GitHub ↗
(ctx)

Source from the content-addressed store, hash-verified

774 },
775 newMessages,
776 contextModifier(ctx) {
777 let modifiedContext = ctx
778
779 // Update allowed tools if specified
780 if (allowedTools.length > 0) {
781 // Capture the current getAppState to chain modifications properly
782 const previousGetAppState = modifiedContext.getAppState
783 modifiedContext = {
784 ...modifiedContext,
785 getAppState() {
786 // Use the previous getAppState, not the closure's context.getAppState,
787 // to properly chain context modifications
788 const appState = previousGetAppState()
789 return {
790 ...appState,
791 toolPermissionContext: {
792 ...appState.toolPermissionContext,
793 alwaysAllowRules: {
794 ...appState.toolPermissionContext.alwaysAllowRules,
795 command: [
796 ...new Set([
797 ...(appState.toolPermissionContext.alwaysAllowRules
798 .command || []),
799 ...allowedTools,
800 ]),
801 ],
802 },
803 },
804 }
805 },
806 }
807 }
808
809 // Carry [1m] suffix over — otherwise a skill with `model: opus` on an
810 // opus[1m] session drops the effective window to 200K and trips autocompact.
811 if (model) {
812 modifiedContext = {
813 ...modifiedContext,
814 options: {
815 ...modifiedContext.options,
816 mainLoopModel: resolveSkillModelOverride(
817 model,
818 ctx.options.mainLoopModel,
819 ),
820 },
821 }
822 }
823
824 // Override effort level if skill specifies one
825 if (effort !== undefined) {
826 const previousGetAppState = modifiedContext.getAppState
827 modifiedContext = {
828 ...modifiedContext,
829 getAppState() {
830 const appState = previousGetAppState()
831 return {
832 ...appState,
833 effortValue: effort,

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected