@theronap/agnoclast-mcp 0.9.261 → 0.9.262

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.
@@ -106,6 +106,7 @@ if (cmd === '--help' || cmd === '-h' || cmd === 'help') {
106
106
  ` uninstall remove ALL Agnoclast wiring (MCP, hooks, skills, launchd, cron). --dry-run to preview, --purge to also wipe ~/.cortex + npx cache\n` +
107
107
  ` doctor live health check — confirm your token works (no restart needed)\n` +
108
108
  ` status one-line connected/not-connected check (used by the SessionStart hook)\n` +
109
+ ` channel [stable|latest] which npm dist-tag this machine's hooks + MCP follow (no arg = show; recorded in ~/.cortex/config.json)\n` +
109
110
  ` use-brain [<brain>] where your session captures are saved — no arg shows the current setting\n` +
110
111
  ` skills install/repair the managed Agnoclast skills — bundled + org-published (also wired by setup)\n` +
111
112
  ` skills push <file> publish a SKILL.md to your org (owner/manager/admin)\n` +
@@ -169,6 +170,12 @@ if (cmd === 'login') {
169
170
  process.exitCode = await runDoctor()
170
171
  const { closeFetch } = await import('../lib/diagnose.mjs')
171
172
  await closeFetch()
173
+ } else if (cmd === 'channel') {
174
+ // Which dist-tag this machine follows: `channel latest` (dogfood) / `channel stable` (everyone's
175
+ // default) / no arg = report. Recorded in ~/.cortex/config.json; every writer of hooks and MCP
176
+ // entries honours it (lib/channel.mjs). File-only, no network, no token needed.
177
+ const { runChannel } = await import('../lib/channel.mjs')
178
+ process.exitCode = runChannel(rest)
172
179
  } else if (cmd === 'status') {
173
180
  // One-line SessionStart health signal (wired by setup). Always exit 0.
174
181
  const { runStatus } = await import('../lib/doctor.mjs')
@@ -0,0 +1,277 @@
1
+ // Which npm dist-tag THIS MACHINE's Agnoclast wiring follows: `@stable` (everyone, the default) or
2
+ // `@latest` (a dogfooding machine that wants every publish the moment it lands).
3
+ //
4
+ // 🔴 WHY THIS IS AN EXPLICIT SETTING AND NOT AN INFERENCE ANY MORE (2026-10-23).
5
+ // Until now the channel was inferred from what was already wired (diagnose.mjs wiredDistTag): "if the
6
+ // MCP entry says @latest, keep @latest". Every writer — setup, repair, install, the desktop app's
7
+ // self-heal (which runs setup) — re-derived it from the config it was about to overwrite. That chain
8
+ // broke silently on Theron's own Mac: the inference read `mcpServers.cortex` only, the ADR-0033 C2
9
+ // flip had moved his @latest entry to `mcpServers.agnoclast`, setup then re-created a `cortex` entry
10
+ // at @stable beside it, and from then on every heal read "stable" and wrote @stable into all five
11
+ // managed hooks. He believed he was on @latest; every hook change published that day never reached
12
+ // him. An inference whose input is its own previous output cannot be trusted to hold a decision.
13
+ //
14
+ // So the decision is RECORDED, once, by a person: `cortex-mcp channel latest`. It lives in
15
+ // ~/.cortex/config.json, which no writer of hooks or MCP entries ever writes to. Every writer asks
16
+ // resolveChannel() and gets the recorded answer first; the wired inference is only the fallback for
17
+ // machines that never chose. Default is stable, for everyone who never ran the command.
18
+ import { homedir } from 'node:os'
19
+ import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs'
20
+ import { join, dirname } from 'node:path'
21
+ import { wiredDistTag } from './diagnose.mjs'
22
+ import { isManagedCommand } from './managed.mjs'
23
+ import { backupFile } from './editors/_fsutil.mjs'
24
+
25
+ export const CHANNELS = ['stable', 'latest']
26
+ export const DEFAULT_CHANNEL = 'stable'
27
+ const PKG = '@theronap/cortex-mcp'
28
+
29
+ /** Where the per-machine choice lives. ~/.cortex is the directory this package already owns. */
30
+ export const channelConfigPath = (home = homedir()) => join(home, '.cortex', 'config.json')
31
+
32
+ /** The command a person runs to choose. Run it through @latest so it works even from a @stable seat. */
33
+ export const channelCommand = (channel) => `npx -y ${PKG}@latest channel ${channel}`
34
+
35
+ const isChannel = (c) => CHANNELS.includes(c)
36
+
37
+ /** The recorded choice, or null if this machine never chose. Never throws. */
38
+ export function readChannelSetting(home = homedir()) {
39
+ try {
40
+ const p = channelConfigPath(home)
41
+ if (!existsSync(p)) return null
42
+ const c = JSON.parse(readFileSync(p, 'utf8') || '{}')?.channel
43
+ return isChannel(c) ? c : null
44
+ } catch {
45
+ return null
46
+ }
47
+ }
48
+
49
+ /** Record the choice. Preserves any other keys in config.json. Throws on a bad channel. */
50
+ export function writeChannelSetting(channel, home = homedir()) {
51
+ if (!isChannel(channel)) throw new Error(`channel must be one of: ${CHANNELS.join(', ')}`)
52
+ const p = channelConfigPath(home)
53
+ let cfg = {}
54
+ try { if (existsSync(p)) cfg = JSON.parse(readFileSync(p, 'utf8') || '{}') ?? {} } catch { cfg = {} }
55
+ if (typeof cfg !== 'object' || Array.isArray(cfg)) cfg = {}
56
+ cfg.channel = channel
57
+ mkdirSync(dirname(p), { recursive: true })
58
+ writeFileSync(p, JSON.stringify(cfg, null, 2) + '\n')
59
+ return p
60
+ }
61
+
62
+ /**
63
+ * The channel this machine follows, and why. Every writer of hooks / MCP entries calls this.
64
+ * source 'config' — recorded with `channel`; authoritative, nothing overrides it
65
+ * source 'wired' — no record, but an MCP entry is deliberately on @latest (legacy dogfood pin)
66
+ * source 'default' — no record, nothing on @latest: stable
67
+ */
68
+ export function resolveChannel({ home = homedir(), wired } = {}) {
69
+ const set = readChannelSetting(home)
70
+ if (set) return { channel: set, source: 'config' }
71
+ const w = wired === undefined ? wiredDistTag(home) : wired
72
+ if (w === 'latest') return { channel: 'latest', source: 'wired' }
73
+ return { channel: DEFAULT_CHANNEL, source: 'default' }
74
+ }
75
+
76
+ /** The package spec for a channel. Always a moving tag, never a bare spec or a frozen version. */
77
+ export function specFor(channel, pkg = PKG) {
78
+ return channel === 'latest' ? `${pkg}@latest` : `${pkg}@stable`
79
+ }
80
+
81
+ /** Convenience: the spec every writer should wire on this machine. */
82
+ export function channelSpec({ home = homedir(), wired } = {}) {
83
+ return specFor(resolveChannel({ home, wired }).channel)
84
+ }
85
+
86
+ // ── What is actually wired, and what disagrees ───────────────────────────────────────────────────
87
+ //
88
+ // Only moving TAGS are compared. A version-floored range (`@^0.9.177`, the arrivals-notice hook —
89
+ // see editors/claude.mjs for why it does not follow `spec`) is deliberate and is never "wrong".
90
+
91
+ const TAG_RE = /@theronap\/(?:cortex|agnoclast)-mcp@(stable|latest)(?![\w.-])/
92
+ const TAG_RE_G = /(@theronap\/(?:cortex|agnoclast)-mcp@)(stable|latest)(?![\w.-])/g
93
+
94
+ const tagOf = (s) => (String(s ?? '').match(TAG_RE) || [])[1] ?? null
95
+
96
+ function readJsonSoft(p) {
97
+ try { return existsSync(p) ? JSON.parse(readFileSync(p, 'utf8') || '{}') : null } catch { return null }
98
+ }
99
+
100
+ /** Short name for a hook command: the subcommand after the spec ("capture", "skills"). */
101
+ function hookLabel(cmd) {
102
+ const m = String(cmd).match(/-mcp@\S+\s+([a-z][\w-]*)/)
103
+ return m ? m[1] : 'hook'
104
+ }
105
+
106
+ /**
107
+ * Every Agnoclast entry on this machine that names a moving tag: [{ file, what, tag }].
108
+ * File reads only — no network — so it is cheap enough for the SessionStart `status` hook.
109
+ */
110
+ export function wiredEntries(home = homedir()) {
111
+ const out = []
112
+ const claudeJson = join(home, '.claude.json')
113
+ const cfg = readJsonSoft(claudeJson)
114
+ for (const key of ['agnoclast', 'cortex']) {
115
+ const e = cfg?.mcpServers?.[key]
116
+ const tag = e ? tagOf([e.command, ...(e.args ?? [])].join(' ')) : null
117
+ if (tag) out.push({ file: claudeJson, what: `MCP server "${key}"`, tag })
118
+ }
119
+ const settingsJson = join(home, '.claude', 'settings.json')
120
+ const s = readJsonSoft(settingsJson)
121
+ for (const [event, groups] of Object.entries(s?.hooks ?? {})) {
122
+ for (const g of Array.isArray(groups) ? groups : []) {
123
+ for (const h of g?.hooks ?? []) {
124
+ if (!isManagedCommand(h?.command)) continue
125
+ const tag = tagOf(h.command)
126
+ if (tag) out.push({ file: settingsJson, what: `${event} hook "${hookLabel(h.command)}"`, tag })
127
+ }
128
+ }
129
+ }
130
+ const codexToml = join(home, '.codex', 'config.toml')
131
+ try {
132
+ if (existsSync(codexToml)) {
133
+ const tag = tagOf(readFileSync(codexToml, 'utf8'))
134
+ if (tag) out.push({ file: codexToml, what: 'Codex MCP server', tag })
135
+ }
136
+ } catch { /* unreadable → not reported */ }
137
+ const codexHooks = join(home, '.codex', 'hooks.json')
138
+ const ch = readJsonSoft(codexHooks)
139
+ for (const [event, groups] of Object.entries(ch?.hooks ?? {})) {
140
+ for (const g of Array.isArray(groups) ? groups : []) {
141
+ for (const h of g?.hooks ?? []) {
142
+ const tag = isManagedCommand(h?.command) ? tagOf(h.command) : null
143
+ if (tag) out.push({ file: codexHooks, what: `Codex ${event} hook "${hookLabel(h.command)}"`, tag })
144
+ }
145
+ }
146
+ }
147
+ const cursorJson = join(home, '.cursor', 'mcp.json')
148
+ const cur = readJsonSoft(cursorJson)
149
+ for (const key of ['agnoclast', 'cortex']) {
150
+ const e = cur?.mcpServers?.[key]
151
+ const tag = e ? tagOf([e.command, ...(e.args ?? [])].join(' ')) : null
152
+ if (tag) out.push({ file: cursorJson, what: `Cursor MCP server "${key}"`, tag })
153
+ }
154
+ return out
155
+ }
156
+
157
+ /** The wired entries whose tag is not `channel`. */
158
+ export function disagreements(channel, home = homedir()) {
159
+ return wiredEntries(home).filter((e) => e.tag !== channel)
160
+ }
161
+
162
+ /**
163
+ * Lines for `status` (SessionStart) and `channel` (no args). SILENT for the common case — a default
164
+ * stable seat whose wiring agrees — because status is re-read on every turn of every session and a
165
+ * line that is always true is noise. It speaks when the machine follows @latest (so the person can see
166
+ * the choice held) and whenever anything disagrees (so a demotion can never be silent again).
167
+ */
168
+ export function channelStatusLines(home = homedir(), { verbose = false } = {}) {
169
+ const { channel, source } = resolveChannel({ home })
170
+ const bad = disagreements(channel, home)
171
+ const lines = []
172
+ const why = source === 'config' ? 'set on this machine' : source === 'wired' ? 'inferred from the MCP entry — not recorded' : 'default'
173
+ if (verbose || channel !== DEFAULT_CHANNEL || source === 'config' || bad.length) {
174
+ lines.push(`Agnoclast: channel @${channel} (${why}).`)
175
+ }
176
+ if (bad.length) {
177
+ const list = bad.map((b) => `${b.what} → @${b.tag}`).join(', ')
178
+ lines.push(`Agnoclast: ⚠ ${bad.length} entr${bad.length === 1 ? 'y' : 'ies'} not on @${channel}: ${list}. Fix: ${channelCommand(channel)}`)
179
+ }
180
+ return lines
181
+ }
182
+
183
+ // ── Applying a choice to what is already wired ───────────────────────────────────────────────────
184
+
185
+ /** PURE. Rewrite every moving tag of our package in a string to `channel`. Ranges/versions untouched. */
186
+ export function respecText(text, channel) {
187
+ return String(text ?? '').replace(TAG_RE_G, (_, pre) => `${pre}${channel}`)
188
+ }
189
+
190
+ /** PURE. Settings/hooks object with every MANAGED hook command re-tagged. Unmanaged hooks untouched. */
191
+ export function respecHooks(obj, channel) {
192
+ let n = 0
193
+ for (const groups of Object.values(obj?.hooks ?? {})) {
194
+ for (const g of Array.isArray(groups) ? groups : []) {
195
+ for (const h of g?.hooks ?? []) {
196
+ if (!isManagedCommand(h?.command)) continue
197
+ const next = respecText(h.command, channel)
198
+ if (next !== h.command) { h.command = next; n++ }
199
+ }
200
+ }
201
+ }
202
+ return n
203
+ }
204
+
205
+ /** PURE. mcpServers object with our entries (agnoclast/cortex) re-tagged. Token/env untouched. */
206
+ export function respecMcp(cfg, channel) {
207
+ let n = 0
208
+ for (const key of ['agnoclast', 'cortex']) {
209
+ const e = cfg?.mcpServers?.[key]
210
+ if (!e || !Array.isArray(e.args)) continue
211
+ const next = e.args.map((a) => (typeof a === 'string' ? respecText(a, channel) : a))
212
+ if (next.some((a, i) => a !== e.args[i])) { e.args = next; n++ }
213
+ }
214
+ return n
215
+ }
216
+
217
+ /**
218
+ * Re-tag everything already wired on this machine to `channel`, in place, backing up each file it
219
+ * changes. Touches ONLY our entries' tags — no token rewrite, no skills install, no network — so it
220
+ * is safe to run from any version. Returns [{ file, changed }].
221
+ */
222
+ export function applyChannel(channel, home = homedir()) {
223
+ const results = []
224
+ const edit = (file, mutate) => {
225
+ const obj = readJsonSoft(file)
226
+ if (!obj) return
227
+ const n = mutate(obj)
228
+ if (n > 0) {
229
+ backupFile(file)
230
+ writeFileSync(file, JSON.stringify(obj, null, 2))
231
+ results.push({ file, changed: n })
232
+ }
233
+ }
234
+ edit(join(home, '.claude.json'), (o) => respecMcp(o, channel))
235
+ edit(join(home, '.claude', 'settings.json'), (o) => respecHooks(o, channel))
236
+ edit(join(home, '.codex', 'hooks.json'), (o) => respecHooks(o, channel))
237
+ edit(join(home, '.cursor', 'mcp.json'), (o) => respecMcp(o, channel))
238
+ const codexToml = join(home, '.codex', 'config.toml')
239
+ try {
240
+ if (existsSync(codexToml)) {
241
+ const before = readFileSync(codexToml, 'utf8')
242
+ const after = respecText(before, channel)
243
+ if (after !== before) {
244
+ backupFile(codexToml)
245
+ writeFileSync(codexToml, after)
246
+ results.push({ file: codexToml, changed: 1 })
247
+ }
248
+ }
249
+ } catch { /* unreadable toml: leave it, status will keep reporting it */ }
250
+ return results
251
+ }
252
+
253
+ /** `cortex-mcp channel [stable|latest]`. No argument = report. Returns an exit code. */
254
+ export function runChannel(argv = [], { home = homedir(), out = (m) => process.stdout.write(m + '\n') } = {}) {
255
+ const want = (argv ?? []).find((a) => !String(a).startsWith('-'))
256
+ if (!want) {
257
+ for (const l of channelStatusLines(home, { verbose: true })) out(l)
258
+ const entries = wiredEntries(home)
259
+ for (const e of entries) out(` ${e.tag === resolveChannel({ home }).channel ? '✓' : '✗'} ${e.what} @${e.tag} (${e.file})`)
260
+ if (!entries.length) out(' (nothing wired on this machine)')
261
+ out(`Switch: ${channelCommand('latest')} · back to everyone's channel: ${channelCommand('stable')}`)
262
+ return 0
263
+ }
264
+ if (!isChannel(want)) {
265
+ process.stderr.write(`Usage: npx -y ${PKG}@latest channel [stable|latest]\n`)
266
+ return 1
267
+ }
268
+ const p = writeChannelSetting(want, home)
269
+ out(`✓ This machine now follows @${want} — recorded in ${p}. setup, repair, install and the desktop app all honour it.`)
270
+ const changed = applyChannel(want, home)
271
+ for (const c of changed) out(` ✓ re-tagged ${c.changed} entr${c.changed === 1 ? 'y' : 'ies'} → @${want} in ${c.file} (backup saved)`)
272
+ if (!changed.length) out(' (every wired entry was already on that channel)')
273
+ const left = disagreements(want, home)
274
+ for (const l of left) out(` ⚠ still @${l.tag}: ${l.what} (${l.file})`)
275
+ out('⟳ Fully quit and reopen Claude Code so the MCP server restarts on the new channel.')
276
+ return left.length ? 1 : 0
277
+ }
package/lib/diagnose.mjs CHANGED
@@ -103,8 +103,9 @@ export function readWiredToken(home = homedir()) {
103
103
 
104
104
  // Pure: pull the cortex-mcp dist-tag / version out of a wired command line. Exported for tests.
105
105
  // Returns 'latest' | 'stable' | a version string (e.g. '0.9.4') | null (no cortex-mcp spec present).
106
+ // Both published names (ADR-0033): a seat may be wired to either.
106
107
  export function parseDistTag(line) {
107
- const m = String(line || '').match(/@theronap\/cortex-mcp@(latest|stable|[0-9][^\s"']*)/)
108
+ const m = String(line || '').match(/@theronap\/(?:cortex|agnoclast)-mcp@(latest|stable|[0-9][^\s"']*)/)
108
109
  return m ? m[1] : null
109
110
  }
110
111
 
@@ -112,11 +113,23 @@ export function parseDistTag(line) {
112
113
  // command), so a re-run of setup/repair can PRESERVE an intentional channel instead of forcing @stable
113
114
  // every time — that silently knocks a dogfooder on @latest back to the pilot channel (bit Theron
114
115
  // 2026-07-24). Returns 'latest' | 'stable' | a version string | null (nothing wired yet).
115
- export function wiredDistTag() {
116
+ //
117
+ // ⚠ BOTH CONFIG KEYS, AND @latest WINS (fixed 2026-10-23). This read `mcpServers.cortex` only. ADR-0033
118
+ // C2 moved the entry to `mcpServers.agnoclast`, so on a migrated machine it found nothing — or, worse,
119
+ // found a `cortex` entry that setup itself had re-created at @stable next to the @latest `agnoclast`
120
+ // one — and every repair/desktop heal wrote @stable into the hooks. That is how Theron's own machine,
121
+ // which he had deliberately put on @latest, was quietly following @stable. An explicit per-machine
122
+ // setting (lib/channel.mjs, `~/.cortex/config.json`) now outranks this inference entirely; this is
123
+ // only the fallback for machines that never ran `channel`.
124
+ export function wiredDistTag(home = homedir()) {
116
125
  try {
117
- const cfg = JSON.parse(readFileSync(join(homedir(), '.claude.json'), 'utf8'))
118
- const c = cfg?.mcpServers?.cortex
119
- return parseDistTag([c?.command, ...(c?.args ?? [])].filter(Boolean).join(' '))
126
+ const cfg = JSON.parse(readFileSync(join(home, '.claude.json'), 'utf8'))
127
+ const tags = ['agnoclast', 'cortex'].map((k) => {
128
+ const c = cfg?.mcpServers?.[k]
129
+ return c ? parseDistTag([c?.command, ...(c?.args ?? [])].filter(Boolean).join(' ')) : null
130
+ })
131
+ if (tags.includes('latest')) return 'latest'
132
+ return tags.find((t) => t) ?? null
120
133
  } catch { /* fall through */ }
121
134
  return null
122
135
  }
package/lib/doctor.mjs CHANGED
@@ -7,6 +7,7 @@ import { detectSurface, renderSurface } from './surface.mjs'
7
7
  import { queueDir, queueStatus, renderQueueNotice } from './capture_queue.mjs'
8
8
  import { pendingNotice, renderReportNotice } from './report_spool.mjs'
9
9
  import { compactNotice } from './session_start_compact.mjs'
10
+ import { channelStatusLines } from './channel.mjs'
10
11
 
11
12
  /** ADR-0070 §5: issue reports filed in the BACKGROUND since the last session start. A background
12
13
  * auto-file had no turn to tell anyone in, so this is where the person hears about it. Consumes the
@@ -58,6 +59,9 @@ export async function runStatus(opts = {}) {
58
59
  } finally {
59
60
  for (const line of queueLines) out(line)
60
61
  for (const line of reportLines) out(line)
62
+ // Which dist-tag this machine follows, and anything wired that disagrees. Silent on a default
63
+ // stable seat that agrees (lib/channel.mjs) — a demotion off @latest is never silent again.
64
+ try { for (const line of channelStatusLines(opts.home)) out(line) } catch { /* never break status */ }
61
65
  const surface = renderSurface(detectSurface(process.env), 'status')
62
66
  if (surface) out(surface)
63
67
  }
@@ -7,12 +7,23 @@ import { join } from 'node:path'
7
7
  import { readJson, backupFile, ensureDir, writeJson } from './_fsutil.mjs'
8
8
  import { markCommand, isManagedSubcommand } from '../managed.mjs'
9
9
 
10
- /** Merge the Agnoclast MCP server into a ~/.claude.json object. Pure + idempotent: sets only the
11
- * `cortex` entry (type:'stdio'), preserves every other server. `spec` = the package@dist-tag string. */
10
+ /** Merge the Agnoclast MCP server into a ~/.claude.json object. Pure + idempotent: sets only OUR
11
+ * entry (type:'stdio'), preserves every other server. `spec` = the package@dist-tag string.
12
+ *
13
+ * ⚠ WHICH KEY: the one already there. ADR-0033 C2 (`migrate-key`) moves `cortex` → `agnoclast`. This
14
+ * used to write `cortex` unconditionally, so a re-run of setup on a migrated machine RE-CREATED a
15
+ * `cortex` entry beside the `agnoclast` one: two Agnoclast servers, and the new one at whatever tag
16
+ * setup picked — which is how Theron's machine ended up with `agnoclast`@latest and `cortex`@stable
17
+ * (2026-10-23). Now: update whichever of the two keys exist; only a machine with neither gets
18
+ * `cortex` (fresh installs are still pre-C2). Never deletes a key — removing a duplicate is the
19
+ * person's call, not a side effect of setup. */
12
20
  export function mergeClaudeMcp(existing, spec, token) {
13
21
  const cfg = existing && typeof existing === 'object' ? { ...existing } : {}
14
22
  cfg.mcpServers = cfg.mcpServers && typeof cfg.mcpServers === 'object' ? { ...cfg.mcpServers } : {}
15
- cfg.mcpServers.cortex = { type: 'stdio', command: 'npx', args: ['-y', spec], env: { CORTEX_TOKEN: token } }
23
+ const keys = ['agnoclast', 'cortex'].filter((k) => cfg.mcpServers[k])
24
+ for (const k of keys.length ? keys : ['cortex']) {
25
+ cfg.mcpServers[k] = { type: 'stdio', command: 'npx', args: ['-y', spec], env: { CORTEX_TOKEN: token } }
26
+ }
16
27
  return cfg
17
28
  }
18
29
 
package/lib/install.mjs CHANGED
@@ -7,9 +7,9 @@ import { homedir } from 'node:os'
7
7
  import { existsSync, mkdirSync, writeFileSync, readFileSync } from 'node:fs'
8
8
  import { join, dirname } from 'node:path'
9
9
  import { ADAPTERS, resolveEditors } from './editors/index.mjs'
10
- import { checkToken, resolveBase, readWiredToken, wiredDistTag } from './diagnose.mjs'
10
+ import { checkToken, resolveBase, readWiredToken } from './diagnose.mjs'
11
+ import { channelSpec } from './channel.mjs'
11
12
 
12
- const PKG = '@theronap/cortex-mcp'
13
13
  export const MANIFEST_PATH = join(homedir(), '.cortex', 'editors.json')
14
14
 
15
15
  /** Parse install argv: an optional positional <token> + `--editor auto|all|<id,...>` (also `--all`,
@@ -70,7 +70,8 @@ export async function runInstall(argv, version) {
70
70
  const token = argToken || readWiredToken()
71
71
  // Preserve an intentional @latest (dogfood) pin across re-runs; fresh installs + existing @stable
72
72
  // get @stable. See wiredDistTag — forcing @stable here silently demoted a dogfooder (2026-07-24).
73
- const spec = wiredDistTag() === 'latest' ? `${PKG}@latest` : `${PKG}@stable`
73
+ // A recorded per-machine channel (lib/channel.mjs) outranks that inference.
74
+ const spec = channelSpec()
74
75
  const home = homedir()
75
76
  const log = (m) => process.stdout.write(m + '\n')
76
77
 
package/lib/setup.mjs CHANGED
@@ -1,7 +1,8 @@
1
1
  import { readFileSync, writeFileSync, existsSync, mkdirSync, copyFileSync } from 'fs'
2
2
  import { homedir } from 'os'
3
3
  import { join, dirname } from 'path'
4
- import { checkToken, resolveBase, readWiredToken, wiredDistTag } from './diagnose.mjs'
4
+ import { checkToken, resolveBase, readWiredToken } from './diagnose.mjs'
5
+ import { resolveChannel } from './channel.mjs'
5
6
  import { installSkills } from './skills.mjs'
6
7
  // Pure config-merge functions live in the editor adapters; setup imports (and re-exports) THE SAME
7
8
  // functions the `cortex install` path uses, so both write byte-identical config.
@@ -28,6 +29,12 @@ export function pickSpec(distTag, pkg = PKG) {
28
29
  return distTag === 'latest' ? `${pkg}@latest` : `${pkg}@stable`
29
30
  }
30
31
 
32
+ // The spec setup/repair (and so the desktop app, which runs setup) wires on this machine: the
33
+ // recorded channel first, then the wired @latest inference, then @stable. Exported for tests.
34
+ export function setupSpec({ home } = {}) {
35
+ return pickSpec(resolveChannel({ home }).channel)
36
+ }
37
+
31
38
  // PURE, exported for tests. Returns { token } or { error } — the caller owns process.exit, so the
32
39
  // validation itself is reachable from a test runner.
33
40
  export function parseSetupArgs(argv, pkg = PKG) {
@@ -68,7 +75,9 @@ export async function runSetup(argv, version) {
68
75
  // npm dist-tag add @theronap/cortex-mcp@<version> stable
69
76
  // PRESERVE an intentional @latest (dogfood) pin across re-runs (repair/setup) — otherwise this
70
77
  // silently knocks a dogfooder back to @stable. Fresh installs and existing @stable get @stable.
71
- const spec = pickSpec(wiredDistTag())
78
+ // The machine's RECORDED channel (`cortex-mcp channel latest`, ~/.cortex/config.json) outranks the
79
+ // wired inference — see lib/channel.mjs for the demotion that made inference alone untrustworthy.
80
+ const spec = setupSpec()
72
81
  const base = resolveBase(process.env.CORTEX_URL)
73
82
  const home = homedir()
74
83
  const claudeJson = join(home, '.claude.json')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theronap/agnoclast-mcp",
3
- "version": "0.9.261",
3
+ "version": "0.9.262",
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": {