@theronap/cortex-mcp 0.9.31 → 0.9.32

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.
Files changed (2) hide show
  1. package/lib/setup.mjs +42 -1
  2. package/package.json +1 -1
package/lib/setup.mjs CHANGED
@@ -61,6 +61,28 @@ function ensureDir(path) {
61
61
  if (!existsSync(dir)) mkdirSync(dir, { recursive: true })
62
62
  }
63
63
 
64
+ // Merge the capture Stop hook into a Codex hooks.json object. Pure + idempotent: drops any prior
65
+ // cortex capture entry (old token / old path / old pinned version) before appending the current one,
66
+ // so re-running never duplicates and never leaves a stale version pinned behind a live one.
67
+ // Mirrors the Claude Stop-hook merge in step 2 below, minus the SessionStart/PreCompact hooks Codex
68
+ // doesn't support (confirmed: Codex's hook runtime only recognizes PreToolUse/PostToolUse/PreCompact/
69
+ // UserPromptSubmit/Stop — no SessionStart, so status/skills-repair/snapshot-context stay Claude-only).
70
+ export function mergeCodexHooks(existing, captureCmd) {
71
+ const h = existing && typeof existing === 'object' ? existing : {}
72
+ h.hooks = h.hooks && typeof h.hooks === 'object' ? h.hooks : {}
73
+ h.hooks.Stop = Array.isArray(h.hooks.Stop) ? h.hooks.Stop : []
74
+ for (const grp of h.hooks.Stop) {
75
+ if (Array.isArray(grp.hooks)) {
76
+ grp.hooks = grp.hooks.filter((c) => !/cortex-mcp.*capture|capture-session-cloud/.test(c.command ?? ''))
77
+ }
78
+ }
79
+ let grp = h.hooks.Stop.find((g) => (g.matcher ?? '') === '')
80
+ if (!grp) { grp = { matcher: '', hooks: [] }; h.hooks.Stop.push(grp) }
81
+ grp.hooks = grp.hooks ?? []
82
+ grp.hooks.push({ type: 'command', command: captureCmd })
83
+ return h
84
+ }
85
+
64
86
  export async function runSetup(argv, version) {
65
87
  const token = argv[0]
66
88
  if (!token || token.startsWith('-')) {
@@ -110,7 +132,7 @@ export async function runSetup(argv, version) {
110
132
 
111
133
  // ── 1b. MCP server in Codex (~/.codex/config.toml), only if Codex is installed ──
112
134
  // Codex gets the same Cortex context tools as Claude Code. Non-fatal: a Codex hiccup must
113
- // never block the primary Claude wiring. Capture/skills self-heal stay Claude-driven for now.
135
+ // never block the primary Claude wiring.
114
136
  const codexDir = join(home, '.codex')
115
137
  if (existsSync(codexDir)) {
116
138
  try {
@@ -122,6 +144,25 @@ export async function runSetup(argv, version) {
122
144
  } catch (e) {
123
145
  log(` ⚠ Codex MCP wiring skipped: ${e.message} (Claude wiring unaffected)`)
124
146
  }
147
+
148
+ // ── 1c. Capture Stop hook in Codex (~/.codex/hooks.json) ──
149
+ // Without this, Codex sessions get context tools + skills but never capture — a silent gap
150
+ // (found 2026-07-02: a hand-set hook on Theron's machine was pinned to a stale 0.4.5, years
151
+ // behind `stable`, because nothing in setup/repair ever refreshed it). Same idempotent
152
+ // merge pattern as the Claude Stop hook below; non-fatal on failure.
153
+ try {
154
+ const codexHooks = join(codexDir, 'hooks.json')
155
+ let existingHooks
156
+ try { existingHooks = readJson(codexHooks) } catch { existingHooks = {} } // malformed → start fresh, don't block
157
+ const bak = backup(codexHooks)
158
+ const captureCmd = `CORTEX_TOKEN=${token} npx -y ${spec} capture`
159
+ ensureDir(codexHooks)
160
+ writeFileSync(codexHooks, JSON.stringify(mergeCodexHooks(existingHooks, captureCmd), null, 2))
161
+ log(` ✓ Capture hook → ${codexHooks}${bak ? ' (backup saved)' : ''}`)
162
+ log(' Codex will ask you to re-approve this hook once (it hashes hooks.json for tamper-detection).')
163
+ } catch (e) {
164
+ log(` ⚠ Codex capture hook skipped: ${e.message} (Claude wiring unaffected)`)
165
+ }
125
166
  }
126
167
 
127
168
  // ── 2. Capture Stop hook in ~/.claude/settings.json ──────────────────────
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theronap/cortex-mcp",
3
- "version": "0.9.31",
3
+ "version": "0.9.32",
4
4
  "description": "Connect your AI assistant to Cortex — your org's projects, activity, gaps, and directives, scoped to you.",
5
5
  "type": "module",
6
6
  "bin": {