@theronap/cortex-mcp 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/setup.mjs +44 -0
- package/package.json +1 -1
package/lib/setup.mjs
CHANGED
|
@@ -14,6 +14,34 @@ import { installSkills } from './skills.mjs'
|
|
|
14
14
|
|
|
15
15
|
const PKG = '@theronap/cortex-mcp'
|
|
16
16
|
|
|
17
|
+
// Merge the Cortex MCP server into a Codex config.toml. Pure + idempotent: strips any existing
|
|
18
|
+
// [mcp_servers.cortex] / [mcp_servers.cortex.env] tables (so re-runs update in place rather than
|
|
19
|
+
// duplicating — a duplicate TOML table would break Codex's parser), preserves every other table,
|
|
20
|
+
// and appends a fresh block. Only touches the cortex tables; never rewrites the user's config.
|
|
21
|
+
export function mergeCodexToml(text, spec, token) {
|
|
22
|
+
const targets = new Set(['[mcp_servers.cortex]', '[mcp_servers.cortex.env]'])
|
|
23
|
+
const kept = []
|
|
24
|
+
let skipping = false
|
|
25
|
+
for (const line of (text || '').split('\n')) {
|
|
26
|
+
const t = line.trim()
|
|
27
|
+
if (t.startsWith('[') && t.endsWith(']')) skipping = targets.has(t)
|
|
28
|
+
if (!skipping) kept.push(line)
|
|
29
|
+
}
|
|
30
|
+
while (kept.length && kept[kept.length - 1].trim() === '') kept.pop() // drop trailing blanks
|
|
31
|
+
const block = [
|
|
32
|
+
'',
|
|
33
|
+
'[mcp_servers.cortex]',
|
|
34
|
+
'command = "npx"',
|
|
35
|
+
`args = ["-y", "${spec}"]`,
|
|
36
|
+
'startup_timeout_sec = 60', // first npx fetch can be slow; don't time out the server on cold start
|
|
37
|
+
'',
|
|
38
|
+
'[mcp_servers.cortex.env]',
|
|
39
|
+
`CORTEX_TOKEN = "${token}"`,
|
|
40
|
+
'',
|
|
41
|
+
]
|
|
42
|
+
return [...kept, ...block].join('\n')
|
|
43
|
+
}
|
|
44
|
+
|
|
17
45
|
function readJson(path) {
|
|
18
46
|
if (!existsSync(path)) return {}
|
|
19
47
|
const raw = readFileSync(path, 'utf8').trim()
|
|
@@ -77,6 +105,22 @@ export async function runSetup(argv, version) {
|
|
|
77
105
|
process.exit(1)
|
|
78
106
|
}
|
|
79
107
|
|
|
108
|
+
// ── 1b. MCP server in Codex (~/.codex/config.toml), only if Codex is installed ──
|
|
109
|
+
// Codex gets the same Cortex context tools as Claude Code. Non-fatal: a Codex hiccup must
|
|
110
|
+
// never block the primary Claude wiring. Capture/skills self-heal stay Claude-driven for now.
|
|
111
|
+
const codexDir = join(home, '.codex')
|
|
112
|
+
if (existsSync(codexDir)) {
|
|
113
|
+
try {
|
|
114
|
+
const codexToml = join(codexDir, 'config.toml')
|
|
115
|
+
const existing = existsSync(codexToml) ? readFileSync(codexToml, 'utf8') : ''
|
|
116
|
+
const bak = backup(codexToml)
|
|
117
|
+
writeFileSync(codexToml, mergeCodexToml(existing, spec, token))
|
|
118
|
+
log(` ✓ MCP server → ${codexToml}${bak ? ' (backup saved)' : ''}`)
|
|
119
|
+
} catch (e) {
|
|
120
|
+
log(` ⚠ Codex MCP wiring skipped: ${e.message} (Claude wiring unaffected)`)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
80
124
|
// ── 2. Capture Stop hook in ~/.claude/settings.json ──────────────────────
|
|
81
125
|
try {
|
|
82
126
|
let s
|