fix(codex): register context7 in TS installer

This commit is contained in:
YeonGyu-Kim
2026-05-31 10:56:36 +09:00
parent 10fcfd994c
commit f84ef382fd
4 changed files with 121 additions and 43 deletions
+4 -43
View File
@@ -1,7 +1,9 @@
import { mkdir, readFile, writeFile } from "node:fs/promises"
import { dirname } from "node:path"
import { ensureContext7McpServer } from "./codex-config-mcp"
import { ensureAutonomousPermissions } from "./codex-config-permissions"
import { ensureCodexMultiAgentV2Config } from "./codex-multi-agent-v2-config"
import { appendBlock, findTomlSection, removeSetting, replaceOrInsertSetting } from "./toml-section-editor"
import { appendBlock, findTomlSection, replaceOrInsertSetting } from "./toml-section-editor"
import type { CodexAgentConfig, CodexMarketplaceSource, TrustedHookState } from "./types"
const SISYPHUS_LEGACY_MARKETPLACES = ["lazycodex", "code-yeongyu-codex-plugins"] as const
@@ -43,6 +45,7 @@ export async function updateCodexConfig(input: {
config = ensureFeatureEnabled(config, "plugins")
config = ensureFeatureEnabled(config, "plugin_hooks")
config = ensureCodexMultiAgentV2Config(config)
config = ensureContext7McpServer(config)
if (input.autonomousPermissions === true) config = ensureAutonomousPermissions(config)
config = ensureMarketplaceBlock(config, input.marketplaceName, input.marketplaceSource)
for (const pluginName of input.pluginNames) {
@@ -111,48 +114,6 @@ function ensureFeatureEnabled(config: string, featureName: string): string {
return replaceOrInsertSetting(config, section, featureName, "true")
}
function ensureAutonomousPermissions(config: string): string {
let next = replaceOrInsertRootSetting(config, "approval_policy", JSON.stringify("never"))
next = replaceOrInsertRootSetting(next, "sandbox_mode", JSON.stringify("danger-full-access"))
next = replaceOrInsertRootSetting(next, "network_access", JSON.stringify("enabled"))
next = removeWindowsSandboxSetting(next)
next = ensureNoticeEnabled(next, "hide_full_access_warning")
return ensureNoticeEnabled(next, "hide_world_writable_warning")
}
function removeWindowsSandboxSetting(config: string): string {
const section = findTomlSection(config, "windows")
if (!section) return config
return removeSetting(config, section, "sandbox")
}
function ensureNoticeEnabled(config: string, key: string): string {
const section = findTomlSection(config, "notice")
if (!section) return appendBlock(config, `[notice]\n${key} = true\n`)
return replaceOrInsertSetting(config, section, key, "true")
}
function replaceOrInsertRootSetting(config: string, key: string, value: string): string {
const sectionStart = findFirstTableStart(config)
const root = config.slice(0, sectionStart)
const suffix = config.slice(sectionStart)
const linePattern = new RegExp(`^${escapeRegExp(key)}\\s*=.*$`, "m")
const replacement = linePattern.test(root)
? root.replace(linePattern, `${key} = ${value}`)
: `${root.trimEnd()}${root.trimEnd().length > 0 ? "\n" : ""}${key} = ${value}\n`
if (suffix.length === 0) return replacement
return `${replacement.trimEnd()}\n\n${suffix.trimStart()}`
}
function findFirstTableStart(config: string): number {
const match = config.match(/^[[].*$/m)
return match?.index ?? config.length
}
function escapeRegExp(value: string): string {
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
}
function ensureMarketplaceBlock(config: string, marketplaceName: string, source: CodexMarketplaceSource): string {
const header = `marketplaces.${marketplaceName}`
const lines = [