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

Function saveCurrentProjectConfig

src/utils/config.ts:1693–1796  ·  view source on GitHub ↗
(
  updater: (currentConfig: ProjectConfig) => ProjectConfig,
)

Source from the content-addressed store, hash-verified

1691}
1692
1693export function saveCurrentProjectConfig(
1694 updater: (currentConfig: ProjectConfig) => ProjectConfig,
1695): void {
1696 if (process.env.NODE_ENV === 'test') {
1697 const config = updater(TEST_PROJECT_CONFIG_FOR_TESTING)
1698 // Skip if no changes (same reference returned)
1699 if (config === TEST_PROJECT_CONFIG_FOR_TESTING) {
1700 return
1701 }
1702 Object.assign(TEST_PROJECT_CONFIG_FOR_TESTING, config)
1703 return
1704 }
1705 const absolutePath = getProjectPathForConfig()
1706 const globalConfigFile = getGlobalNcodeFile()
1707
1708 if (blockedConfigWrites.has(globalConfigFile)) {
1709 const config =
1710 globalConfigCache.config ?? getConfig(globalConfigFile, createDefaultGlobalConfig)
1711 const currentProjectConfig =
1712 config.projects?.[absolutePath] ?? DEFAULT_PROJECT_CONFIG
1713 const newProjectConfig = updater(currentProjectConfig)
1714 if (newProjectConfig === currentProjectConfig) {
1715 return
1716 }
1717 writeThroughGlobalConfigCache({
1718 ...config,
1719 projects: {
1720 ...config.projects,
1721 [absolutePath]: newProjectConfig,
1722 },
1723 })
1724 return
1725 }
1726
1727 let written: GlobalConfig | null = null
1728 try {
1729 const didWrite = saveConfigWithLock(
1730 globalConfigFile,
1731 createDefaultGlobalConfig,
1732 current => {
1733 const currentProjectConfig =
1734 current.projects?.[absolutePath] ?? DEFAULT_PROJECT_CONFIG
1735 const newProjectConfig = updater(currentProjectConfig)
1736 // Skip if no changes (same reference returned)
1737 if (newProjectConfig === currentProjectConfig) {
1738 return current
1739 }
1740 written = {
1741 ...current,
1742 projects: {
1743 ...current.projects,
1744 [absolutePath]: newProjectConfig,
1745 },
1746 }
1747 return written
1748 },
1749 )
1750 if (didWrite && written) {

Callers 15

saveCurrentSessionCostsFunction · 0.85
TrustDialogFunction · 0.85
exampleCommands.tsFile · 0.85
createWorktreeForSessionFunction · 0.85
keepWorktreeFunction · 0.85
cleanupWorktreeFunction · 0.85
bridgeMainFunction · 0.85
onStdinDataFunction · 0.85
flushFunction · 0.85

Calls 10

saveConfigWithLockFunction · 0.85
wouldLoseAuthStateFunction · 0.85
saveConfigFunction · 0.85
getConfigFunction · 0.70
logForDebuggingFunction · 0.70
logEventFunction · 0.50
hasMethod · 0.45

Tested by

no test coverage detected