@theronap/agnoclast-mcp 0.9.277 → 0.9.279

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.
@@ -276,7 +276,7 @@ if (cmd === 'login') {
276
276
  // ADR-0033 §5 C2. Guarded: adds the new namespace's allow rules and VERIFIES them from disk
277
277
  // before flipping mcpServers.cortex -> .agnoclast, so a seat that never received C1 cannot end up
278
278
  // with renamed tools and no permissions. Idempotent; --dry-run reports the plan and changes
279
- // nothing. NOT wired into any hook yet — activating it is the C2 release itself.
279
+ // nothing. Also runs on its own at every server start since 0.9.279 (autoMigrateKeys).
280
280
  const { runKeyMigration } = await import('../lib/migrate_key.mjs')
281
281
  const res = runKeyMigration({ dryRun: rest.includes('--dry-run') })
282
282
  process.stdout.write(JSON.stringify(res, null, 2) + '\n')
@@ -331,6 +331,10 @@ if (cmd === 'login') {
331
331
  // on their next install/repair; drop this branch a release after that has had time to propagate.
332
332
  } else {
333
333
  // Default: run the MCP server (stays alive; never exits).
334
+ // First, finish the cortex -> agnoclast key flip if this machine still has the old key. Best-effort,
335
+ // stderr only (stdout is the MCP channel); see autoMigrateKeys.
336
+ const { autoMigrateKeys } = await import('../lib/migrate_key.mjs')
337
+ autoMigrateKeys()
334
338
  const { runServer } = await import('../lib/server.mjs')
335
339
  await runServer(VERSION)
336
340
  }
@@ -1,5 +1,5 @@
1
1
  // find_documents' answer (file browser, Theron 2026-10-27): every stored file the caller can see, one block
2
- // per file — its page (a file's page is its folder) and brain, and why it matched a search.
2
+ // per file — its page and brain, the folder people filed it in, and why it matched a search.
3
3
 
4
4
  const TYPE_NAMES = { sheet: 'spreadsheet', doc: 'Word', text: 'text', other: 'other' }
5
5
 
@@ -10,8 +10,21 @@ export function formatFoundDocuments(out, query) {
10
10
  for (const f of files) {
11
11
  lines.push(`${f.pinned ? '📌' : '-'} "${f.title}" — id ${f.id} · ${TYPE_NAMES[f.type] ?? f.type} · v${f.version} · ${Math.round(f.sizeBytes / 1024)} KB · ${String(f.updatedAt).slice(0, 10)}${f.updatedBy ? ` by ${f.updatedBy}` : ''}${f.readable === 'ok' ? '' : ' · not readable as text'}`)
12
12
  lines.push(` on ${f.page ? `"${f.page.title ?? 'untitled page'}"` : 'no page (its page was deleted)'} · ${f.brain.name}`)
13
+ const inFolder = folderPathText(out.folders ?? [], f.folderId)
14
+ if (inFolder) lines.push(` in folder "${inFolder}" (folder id ${f.folderId})`)
13
15
  if (f.match?.in === 'text' && f.match.snippet) lines.push(` matched inside: "${f.match.snippet}"`)
14
16
  else if (f.match?.in === 'page') lines.push(' matched its page\'s title')
15
17
  }
16
18
  return lines.join('\n')
17
19
  }
20
+
21
+ // "Finance › Taxes", walking up from a folder; null when the file is not in a folder the caller can see.
22
+ function folderPathText(folders, id) {
23
+ const names = []
24
+ const seen = new Set()
25
+ for (let at = folders.find((x) => x.id === id); at && !seen.has(at.id); at = folders.find((x) => x.id === at.parentId)) {
26
+ seen.add(at.id)
27
+ names.unshift(at.name)
28
+ }
29
+ return names.length ? names.join(' › ') : null
30
+ }
@@ -1,5 +1,5 @@
1
1
  import { homedir } from 'node:os'
2
- import { existsSync } from 'node:fs'
2
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs'
3
3
  import { join } from 'node:path'
4
4
  import { readJson, backupFile, ensureDir, writeJson } from './editors/_fsutil.mjs'
5
5
  import { allowedToolsFor } from './editors/claude.mjs'
@@ -41,6 +41,13 @@ export function migratedMcpServers(servers) {
41
41
  const out = { ...(servers ?? {}) }
42
42
  if (out[NEW_KEY] && !out[OLD_KEY]) return { servers: out, moved: false, reason: 'already-new-key' }
43
43
  if (!out[OLD_KEY]) return { servers: out, moved: false, reason: 'no-entry' }
44
+ // BOTH keys (a pre-0.9.277 setup re-created `cortex` beside a migrated `agnoclast`): the new key is
45
+ // the one to keep — it is the one the person or a newer setup last chose. Copying `cortex` over it
46
+ // would carry the older spec across, which is how a @latest seat gets knocked back to @stable.
47
+ if (out[NEW_KEY]) {
48
+ delete out[OLD_KEY]
49
+ return { servers: out, moved: true, reason: 'dropped-duplicate' }
50
+ }
44
51
  // Carry the entry across untouched: command, args (the package spec) and env all survive, so a
45
52
  // dogfooder pinned to @latest stays pinned and the token is not re-derived.
46
53
  out[NEW_KEY] = out[OLD_KEY]
@@ -79,14 +86,18 @@ export function runKeyMigration({ home = homedir(), dryRun = false, io = {} } =
79
86
  const statePath = migrationStatePath(home)
80
87
  const required = allowedToolsFor(NEW_KEY)
81
88
 
82
- if (exists(statePath)) {
83
- try { if (read(statePath)?.to === NEW_KEY) return { status: 'already', statePath } } catch { /* re-run */ }
84
- }
85
-
89
+ // The config is checked BEFORE the state file. The state file used to short-circuit on its own, so
90
+ // a `cortex` entry re-created after the flip (an older setup run, 2026-10) was never looked at
91
+ // again. "Done" is only true while the config agrees.
86
92
  let cfg
87
93
  try { cfg = read(claudeJson) } catch (e) { return { status: 'aborted', step: 'read-config', reason: e.message } }
88
94
  const plan = migratedMcpServers(cfg?.mcpServers)
89
- if (!plan.moved) return { status: 'nothing-to-migrate', reason: plan.reason }
95
+ if (!plan.moved) {
96
+ if (exists(statePath)) {
97
+ try { if (read(statePath)?.to === NEW_KEY) return { status: 'already', statePath } } catch { /* fall through */ }
98
+ }
99
+ return { status: 'nothing-to-migrate', reason: plan.reason }
100
+ }
90
101
 
91
102
  // ── 1+2. Allowlist FIRST, then verify from disk. ───────────────────────────
92
103
  let settings
@@ -130,10 +141,73 @@ export function runKeyMigration({ home = homedir(), dryRun = false, io = {} } =
130
141
  if (!cfgAfter?.mcpServers?.[NEW_KEY]) {
131
142
  return { status: 'aborted', step: 'verify-config', reason: 'config key did not persist' }
132
143
  }
144
+ if (cfgAfter.mcpServers[OLD_KEY]) {
145
+ return { status: 'aborted', step: 'verify-config', reason: 'old key still present' }
146
+ }
133
147
 
134
148
  // ── 5. Record it. Best-effort: a missing state file only costs an idempotent re-run. ──
135
- const record = { from: OLD_KEY, to: NEW_KEY, allowsAdded: missing.length }
149
+ const record = { from: OLD_KEY, to: NEW_KEY, allowsAdded: missing.length, ...(plan.reason ? { reason: plan.reason } : {}) }
136
150
  try { mkdir(statePath); write(statePath, record) } catch { /* non-fatal */ }
137
151
 
138
152
  return { status: 'migrated', ...record, statePath }
139
153
  }
154
+
155
+ /** PURE. A Codex config.toml with our `cortex` tables renamed to `agnoclast` — or, when `agnoclast`
156
+ * tables are already there, with the `cortex` ones dropped. Returns null when there is nothing to do.
157
+ * Only our two table headers are touched; every other line survives byte for byte. */
158
+ export function migratedCodexToml(text) {
159
+ const lines = (text || '').split('\n')
160
+ const header = (l) => { const t = l.trim(); return t.startsWith('[') && t.endsWith(']') ? t : null }
161
+ const OLD = new Set([`[mcp_servers.${OLD_KEY}]`, `[mcp_servers.${OLD_KEY}.env]`])
162
+ if (!lines.some((l) => OLD.has(header(l)))) return null
163
+ if (lines.some((l) => header(l) === `[mcp_servers.${NEW_KEY}]`)) {
164
+ const kept = []
165
+ let skipping = false
166
+ for (const l of lines) {
167
+ const h = header(l)
168
+ if (h) skipping = OLD.has(h)
169
+ if (!skipping) kept.push(l)
170
+ }
171
+ return kept.join('\n')
172
+ }
173
+ return lines.map((l) => (OLD.has(header(l)) ? l.replace(`mcp_servers.${OLD_KEY}`, `mcp_servers.${NEW_KEY}`) : l)).join('\n')
174
+ }
175
+
176
+ /** Cursor and Codex: the same flip, no allowlist to order against (neither has one). Best-effort per
177
+ * editor; returns what changed. A malformed file is left alone, never rewritten. */
178
+ export function migrateOtherEditors({ home = homedir() } = {}) {
179
+ const changed = []
180
+ const cursor = join(home, '.cursor', 'mcp.json')
181
+ try {
182
+ if (existsSync(cursor)) {
183
+ const cfg = readJson(cursor)
184
+ const plan = migratedMcpServers(cfg?.mcpServers)
185
+ if (plan.moved) { backupFile(cursor); writeJson(cursor, { ...cfg, mcpServers: plan.servers }); changed.push('cursor') }
186
+ }
187
+ } catch { /* leave it */ }
188
+ const codex = join(home, '.codex', 'config.toml')
189
+ try {
190
+ if (existsSync(codex)) {
191
+ const next = migratedCodexToml(readFileSync(codex, 'utf8'))
192
+ if (next !== null) { backupFile(codex); writeFileSync(codex, next); changed.push('codex') }
193
+ }
194
+ } catch { /* leave it */ }
195
+ return changed
196
+ }
197
+
198
+ /** Run at every MCP server start (bin/cortex-mcp.mjs default branch) — the C2 activation that was
199
+ * planned in ADR-0033 and never wired, so seats that were told "it will happen for you" kept the
200
+ * `cortex` key for months. NEVER throws and NEVER writes stdout: stdout is the MCP stdio channel.
201
+ * The new name takes effect at the editor's next start; the running session keeps its servers. */
202
+ export function autoMigrateKeys({ home = homedir(), log = (m) => process.stderr.write(m + '\n') } = {}) {
203
+ try {
204
+ const res = runKeyMigration({ home })
205
+ const others = migrateOtherEditors({ home })
206
+ if (res.status === 'migrated' || others.length) {
207
+ log(`agnoclast: renamed the \`${OLD_KEY}\` MCP entry to \`${NEW_KEY}\` (${[res.status === 'migrated' ? 'claude' : null, ...others].filter(Boolean).join(', ')}); takes effect next restart`)
208
+ }
209
+ return { claude: res, others }
210
+ } catch (e) {
211
+ return { claude: { status: 'aborted', step: 'unexpected', reason: e?.message }, others: [] }
212
+ }
213
+ }
@@ -5,7 +5,7 @@
5
5
  // that web/lib/engine/release.test.ts pins to the server's registry.
6
6
 
7
7
  /** Tools any release flag gates — hidden when the server cannot be asked. Mirror of allGatedTools(). */
8
- export const GATED_FALLBACK = ['arrivals', 'attach_document', 'document_diff', 'export_page', 'file_arrival', 'find_documents', 'get_document', 'import_document_as_page', 'intake_shadow', 'list_documents', 'my_messages', 'pin_document', 'read_conversation', 'read_document', 'send_message', 'set_manager', 'upload_document_version']
8
+ export const GATED_FALLBACK = ['arrivals', 'attach_document', 'document_diff', 'export_page', 'file_arrival', 'file_document', 'find_documents', 'get_document', 'import_document_as_page', 'intake_shadow', 'list_documents', 'my_messages', 'pin_document', 'read_conversation', 'read_document', 'send_message', 'set_manager', 'upload_document_version']
9
9
 
10
10
  export const RELEASE_FETCH_TIMEOUT_MS = 2500
11
11
 
package/lib/server.mjs CHANGED
@@ -7506,23 +7506,25 @@ function renderNudge(payload) {
7506
7506
  'find_documents',
7507
7507
  {
7508
7508
  title: 'Find stored files you can see',
7509
- description: 'Search every file kept in Agnoclast that you can see, across all pages and brains — no page needed. Matches the file name, the page it lives on, or the words inside it (a match inside the file shows the words around it). Newest first; filter by type, brain, page, pinned, or changed since. Each file names its page (a file\'s page is its folder) and brain. Then read_document to read one, document_diff to see what changed, get_document to download it. list_documents is the one-page view.',
7509
+ description: 'Search every file kept in Agnoclast that you can see, across all pages and brains — no page needed. Matches the file name, the page it lives on, or the words inside it (a match inside the file shows the words around it). Newest first; filter by type, brain, page, folder, pinned, or changed since. Each file names its page and brain, and the folder people filed it in, if any (file_document files one). Then read_document to read one, document_diff to see what changed, get_document to download it. list_documents is the one-page view.',
7510
7510
  inputSchema: {
7511
7511
  query: z.string().optional().describe('words to find in the file name, its page\'s title, or the text inside the file'),
7512
7512
  type: z.enum(['sheet', 'doc', 'text', 'other']).optional().describe('sheet = Excel/spreadsheet, doc = Word, text = CSV/plain text'),
7513
7513
  brain: z.string().optional().describe('only this brain (its name or id)'),
7514
7514
  page: z.string().optional().describe('only files on this page (a document id)'),
7515
+ folder: z.string().optional().describe('only files in this folder or the folders inside it (a folder id, printed as "folder id …")'),
7515
7516
  pinned: z.boolean().optional().describe('true = pinned files only'),
7516
7517
  changed_since: z.string().optional().describe('ISO date: only files with a version at or after it'),
7517
7518
  limit: z.number().int().min(1).max(500).optional().describe('default 50'),
7518
7519
  },
7519
7520
  },
7520
- async ({ query, type, brain, page, pinned, changed_since, limit }) => {
7521
+ async ({ query, type, brain, page, folder, pinned, changed_since, limit }) => {
7521
7522
  const q = new URLSearchParams({ limit: String(limit ?? 50) })
7522
7523
  if (query) q.set('q', query)
7523
7524
  if (type) q.set('type', type)
7524
7525
  if (brain) q.set('brain', brain)
7525
7526
  if (page) q.set('page', page)
7527
+ if (folder) q.set('folder', folder)
7526
7528
  if (pinned !== undefined) q.set('pinned', String(pinned))
7527
7529
  if (changed_since) q.set('since', changed_since)
7528
7530
  let res
@@ -7533,6 +7535,31 @@ function renderNudge(payload) {
7533
7535
  },
7534
7536
  )
7535
7537
 
7538
+ server.registerTool(
7539
+ 'file_document',
7540
+ {
7541
+ title: 'Put a stored file in a folder',
7542
+ description: 'File a stored file in one of its brain\'s folders (the folders people make on the Files tab, shared by everyone in the brain), or take it out of its folder. A folder is only a label: it never changes who can open the file — the file\'s page still decides. A file is in at most one folder. Get file_id from find_documents or list_documents; name the folder or pass the "folder id …" find_documents prints.',
7543
+ inputSchema: {
7544
+ file_id: z.string().describe('the stored file\'s id'),
7545
+ folder: z.string().nullable().describe('the folder\'s name (in the file\'s brain) or its id; null to take the file out of its folder'),
7546
+ },
7547
+ },
7548
+ async ({ file_id, folder }) => {
7549
+ let res
7550
+ try {
7551
+ res = await fetchCortex(`${BASE}/api/stored-files/${encodeURIComponent(file_id)}/folder`, {
7552
+ method: 'POST', headers: { Authorization: `Bearer ${TOKEN}`, 'Content-Type': 'application/json' },
7553
+ body: JSON.stringify({ folderId: folder ?? null }),
7554
+ })
7555
+ } catch (e) { return toolError(`Could not file it: ${e.message}`) }
7556
+ if (!res.ok) return docFail('file it', res)
7557
+ const out = await res.json()
7558
+ if (!out.changed) return { content: [{ type: 'text', text: folder ? `It was already in that folder.` : 'It was not in a folder.' }] }
7559
+ return { content: [{ type: 'text', text: folder ? `Filed it in "${folder}" (folder id ${out.folderId}).` : 'Took it out of its folder.' }] }
7560
+ },
7561
+ )
7562
+
7536
7563
  server.registerTool(
7537
7564
  'read_document',
7538
7565
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theronap/agnoclast-mcp",
3
- "version": "0.9.277",
3
+ "version": "0.9.279",
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": {