@theronap/cortex-mcp 0.9.80 → 0.9.81
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/README.md +3 -3
- package/bin/cortex-mcp.mjs +22 -38
- package/lib/capture.mjs +1 -1
- package/lib/code_graph_cli.mjs +1 -1
- package/lib/context_log.mjs +5 -5
- package/lib/diagnose.mjs +11 -81
- package/lib/docs_scan.mjs +4 -4
- package/lib/doctor.mjs +11 -48
- package/lib/editors/antigravity.mjs +1 -1
- package/lib/editors/claude.mjs +14 -29
- package/lib/editors/codex.mjs +1 -1
- package/lib/editors/cursor.mjs +1 -1
- package/lib/editors/index.mjs +1 -1
- package/lib/graphify_sync.mjs +4 -49
- package/lib/grep_cli.mjs +1 -1
- package/lib/hydrate.mjs +1 -1
- package/lib/imessage_send.mjs +1 -1
- package/lib/ingest_folder.mjs +2 -2
- package/lib/install.mjs +6 -6
- package/lib/precompact.mjs +16 -0
- package/lib/redact.mjs +1 -1
- package/lib/resolve.mjs +12 -62
- package/lib/server.mjs +41 -171
- package/lib/setup.mjs +10 -11
- package/lib/skills.mjs +17 -89
- package/lib/uninstall.mjs +3 -3
- package/package.json +1 -1
- package/skills/author-docs/SKILL.md +5 -5
- package/skills/context/SKILL.md +4 -4
- package/skills/log/SKILL.md +6 -6
- package/skills/walkthrough/SKILL.md +1 -1
- package/lib/timeline_claim_receipt.mjs +0 -25
- package/lib/use_brain.mjs +0 -82
package/lib/server.mjs
CHANGED
|
@@ -11,7 +11,6 @@ import { runSendImessage } from './imessage_send.mjs'
|
|
|
11
11
|
import { formatGrepHits } from './grep_cli.mjs'
|
|
12
12
|
import { renderTriage } from './red_link_triage.mjs'
|
|
13
13
|
import { runCodeGraphQuery } from './code_graph_cli.mjs'
|
|
14
|
-
import { renderTimelineClaimReceipt } from './timeline_claim_receipt.mjs'
|
|
15
14
|
|
|
16
15
|
// Reactive red-link triage (Mechanism 2). On a read_page miss, ask the server whether the name is a
|
|
17
16
|
// tracked wanted page, whether a bare node exists for it, and whether it's a deliberately demoted page,
|
|
@@ -41,7 +40,7 @@ async function redLinkTriage(BASE, TOKEN, name) {
|
|
|
41
40
|
// file-request tools, and a module-level `fail` would be silently shadowed by it from that point on.
|
|
42
41
|
const toolError = (text) => ({ content: [{ type: 'text', text }], isError: true })
|
|
43
42
|
|
|
44
|
-
// The
|
|
43
|
+
// The Cortex MCP server (stdio). Serves the signed-in employee's scoped org
|
|
45
44
|
// context to their AI assistant. CORTEX_TOKEN identifies the user + org.
|
|
46
45
|
|
|
47
46
|
export async function runServer(version) {
|
|
@@ -49,7 +48,7 @@ export async function runServer(version) {
|
|
|
49
48
|
const BASE = resolveBase(process.env.CORTEX_URL)
|
|
50
49
|
|
|
51
50
|
if (!TOKEN) {
|
|
52
|
-
process.stderr.write('cortex-mcp: CORTEX_TOKEN is required. Get yours from the
|
|
51
|
+
process.stderr.write('cortex-mcp: CORTEX_TOKEN is required. Get yours from the Cortex console → Connect your AI.\n')
|
|
53
52
|
process.exit(1)
|
|
54
53
|
}
|
|
55
54
|
|
|
@@ -91,7 +90,7 @@ export async function runServer(version) {
|
|
|
91
90
|
const now = Date.now()
|
|
92
91
|
if (cache && now - cache.ts < 5 * 60 * 1000) return cache.text
|
|
93
92
|
// fetchCortex retries transient infra/5xx; classify turns a failure into an honest message
|
|
94
|
-
// (token vs infra-block vs network) instead of a bare "
|
|
93
|
+
// (token vs infra-block vs network) instead of a bare "Cortex API 403: unknown".
|
|
95
94
|
const res = await fetchCortex(`${BASE}/api/mcp-context`, { headers: { Authorization: `Bearer ${TOKEN}` } })
|
|
96
95
|
if (!res.ok) {
|
|
97
96
|
const body = await res.text()
|
|
@@ -118,7 +117,7 @@ export async function runServer(version) {
|
|
|
118
117
|
server.registerTool(
|
|
119
118
|
'my_context',
|
|
120
119
|
{
|
|
121
|
-
title: 'My
|
|
120
|
+
title: 'My Cortex context',
|
|
122
121
|
description: 'Your current work context from the org. Pass a question to get query-centered session context seeded from the most relevant node and its neighborhood; omit it for the baseline snapshot.',
|
|
123
122
|
inputSchema: { question: z.string().optional().describe('optional opening user question to center the context around') },
|
|
124
123
|
},
|
|
@@ -138,53 +137,6 @@ export async function runServer(version) {
|
|
|
138
137
|
},
|
|
139
138
|
)
|
|
140
139
|
|
|
141
|
-
// Where this machine's unattended session captures land. The server half shipped 2026-08-09 with no
|
|
142
|
-
// client surface at all, so the only way to set it was a hand-written authenticated HTTP call —
|
|
143
|
-
// which meant three real users whose sessions were silently being held could not fix it themselves.
|
|
144
|
-
// This is the surface that makes it answerable in conversation: "put my sessions in TTO".
|
|
145
|
-
server.registerTool(
|
|
146
|
-
'set_capture_brain',
|
|
147
|
-
{
|
|
148
|
-
title: 'Choose where your session captures are saved',
|
|
149
|
-
description:
|
|
150
|
-
'Set which brain THIS PERSON\'s unattended session captures (the automatic end-of-session record) land in, or read the current setting by omitting `brain`. WHEN TO USE: whenever the user says their sessions are not being saved, asks where their work is going, or a session-start notice says captures are being HELD. WHY IT IS NEEDED: with more than one brain, a capture that names no brain cannot be routed and is held outside every brain — correct, but invisible, so it accumulates silently. This is per-PERSON and applies to their own captures only; it cannot be set for someone else. ⚠ PASS THE ORG ID when the user has two brains with the SAME NAME (e.g. two called "Personal") — a name matching more than one is REFUSED rather than guessed, and the error lists the ids to choose from. Setting this does NOT file already-held captures; those keep their original dates and may belong in different brains, so sort them deliberately rather than dumping them into the new default.',
|
|
151
|
-
inputSchema: {
|
|
152
|
-
brain: z.string().optional().describe('the brain name or org id (from my_brains) where this person\'s session captures should land. Omit to read the current setting instead of changing it.'),
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
|
-
async ({ brain }) => {
|
|
156
|
-
const url = `${BASE}/api/brain/capture-default`
|
|
157
|
-
if (!brain?.trim()) {
|
|
158
|
-
const res = await fetchCortex(url, { headers: { Authorization: `Bearer ${TOKEN}` } })
|
|
159
|
-
if (!res.ok) {
|
|
160
|
-
const body = await res.text()
|
|
161
|
-
throw new Error(classify(res.status, res.headers.get('content-type'), body, res.headers.get('x-vercel-id')).message)
|
|
162
|
-
}
|
|
163
|
-
const { defaults } = await res.json()
|
|
164
|
-
if (!defaults?.length) {
|
|
165
|
-
return { content: [{ type: 'text', text: 'No capture brain is set. If you belong to more than one brain, your session captures are being HELD outside every brain until you set one. Call this tool again with `brain` to fix it.' }] }
|
|
166
|
-
}
|
|
167
|
-
const lines = defaults.map((d) => `${d.sourceType} captures land in "${d.orgName}" (${d.orgId}), set ${String(d.updatedAt).slice(0, 10)}`)
|
|
168
|
-
return { content: [{ type: 'text', text: lines.join('\n') }] }
|
|
169
|
-
}
|
|
170
|
-
const res = await fetchCortex(url, {
|
|
171
|
-
method: 'POST',
|
|
172
|
-
headers: { Authorization: `Bearer ${TOKEN}`, 'Content-Type': 'application/json' },
|
|
173
|
-
body: JSON.stringify({ sourceType: 'claude-code', brain: brain.trim() }),
|
|
174
|
-
})
|
|
175
|
-
const body = await res.text()
|
|
176
|
-
if (!res.ok) {
|
|
177
|
-
// Prefer the server's own error: a 409 lists the org ids of an ambiguous name, which IS the
|
|
178
|
-
// remedy, and a generic classification would throw that away.
|
|
179
|
-
let msg
|
|
180
|
-
try { msg = JSON.parse(body).error } catch { /* fall through to the classified message */ }
|
|
181
|
-
throw new Error(msg ?? classify(res.status, res.headers.get('content-type'), body, res.headers.get('x-vercel-id')).message)
|
|
182
|
-
}
|
|
183
|
-
const j = JSON.parse(body)
|
|
184
|
-
return { content: [{ type: 'text', text: `✓ Your Claude Code sessions now land in "${j.brain}" (${j.orgId}). Sessions captured before now are still held and keep their original dates — file those deliberately, they may not all belong in this brain.` }] }
|
|
185
|
-
},
|
|
186
|
-
)
|
|
187
|
-
|
|
188
140
|
// T8: cortex-log's authoritative writer. The skill composes a curated summary, then calls this to
|
|
189
141
|
// persist it AS the durable record (capture_source='skill'). The ingest conflict guard ensures the
|
|
190
142
|
// auto-capture hook never clobbers it. Pass the SAME sessionId the hook uses so the two dedupe onto
|
|
@@ -192,8 +144,8 @@ export async function runServer(version) {
|
|
|
192
144
|
server.registerTool(
|
|
193
145
|
'log_session',
|
|
194
146
|
{
|
|
195
|
-
title: 'Log this session to
|
|
196
|
-
description: 'Persist a CURATED summary of this work session as its durable
|
|
147
|
+
title: 'Log this session to Cortex',
|
|
148
|
+
description: 'Persist a CURATED summary of this work session as its durable Cortex record (authoritative — supersedes the auto-capture hook). Call at session close after composing the summary. Pass sessionId (the Claude Code session id) if you have it so this dedupes with the auto-capture of the same session.',
|
|
197
149
|
inputSchema: {
|
|
198
150
|
summary: z.string().describe('the curated session summary (what was done, decided, left open) — becomes the durable record'),
|
|
199
151
|
project: z.string().optional().describe('project key/name this session worked in'),
|
|
@@ -220,7 +172,7 @@ export async function runServer(version) {
|
|
|
220
172
|
throw new Error(classify(res.status, res.headers.get('content-type'), body, res.headers.get('x-vercel-id')).message)
|
|
221
173
|
}
|
|
222
174
|
const j = await res.json().catch(() => ({}))
|
|
223
|
-
return { content: [{ type: 'text', text: `Logged to
|
|
175
|
+
return { content: [{ type: 'text', text: `Logged to Cortex (authoritative): "${j.title ?? title ?? 'session'}" — ${j.inserted ? 'new record' : 'updated existing'}.` }] }
|
|
224
176
|
},
|
|
225
177
|
)
|
|
226
178
|
|
|
@@ -300,12 +252,8 @@ export async function runServer(version) {
|
|
|
300
252
|
const body = await res.text()
|
|
301
253
|
throw new Error(classify(res.status, res.headers.get('content-type'), body, res.headers.get('x-vercel-id')).message)
|
|
302
254
|
}
|
|
303
|
-
const { threads, records
|
|
304
|
-
|
|
305
|
-
if (!threads?.length && !records?.length) {
|
|
306
|
-
const empty = 'Nothing in the backlog — everything captured so far has been claimed.'
|
|
307
|
-
return { content: [{ type: 'text', text: receipt ? `${empty}\n\n${receipt}` : empty }] }
|
|
308
|
-
}
|
|
255
|
+
const { threads, records } = await res.json()
|
|
256
|
+
if (!threads?.length && !records?.length) return { content: [{ type: 'text', text: 'Nothing in the backlog — everything captured so far has been claimed.' }] }
|
|
309
257
|
|
|
310
258
|
const sections = []
|
|
311
259
|
|
|
@@ -334,44 +282,32 @@ export async function runServer(version) {
|
|
|
334
282
|
sections.push(`Unclaimed records (${records.length}) from other sources — newest first:\n${lines.join('\n')}`)
|
|
335
283
|
}
|
|
336
284
|
|
|
337
|
-
if (receipt) sections.push(receipt)
|
|
338
285
|
return { content: [{ type: 'text', text: sections.join('\n\n') }] }
|
|
339
286
|
},
|
|
340
287
|
)
|
|
341
288
|
|
|
342
|
-
// Read-only evidence status for the Gate 4 live trial. This MUST remain an aggregate query: a
|
|
343
|
-
// monitor needs to know whether enough sessions have exercised the loop, not who they were or what
|
|
344
|
-
// work they handled. In particular, it must never call timeline_pull as a shortcut, since that would
|
|
345
|
-
// manufacture the evidence it claims to observe.
|
|
346
289
|
server.registerTool(
|
|
347
|
-
'
|
|
290
|
+
'maintenance_candidates',
|
|
348
291
|
{
|
|
349
|
-
title: '
|
|
350
|
-
description: '
|
|
292
|
+
title: 'Review recent project-linked maintenance evidence',
|
|
293
|
+
description: 'Start here when preparing a handoff, status, or next step for a NAMED project. Returns a bounded, RLS-scoped set of recent raw records already linked to that project, before you trust the authored page. These are candidate evidence, not a command to edit: read them, call project_status, then decide whether a material contradiction warrants a minimal accountable correction. Never mutate merely to clear a candidate.',
|
|
351
294
|
inputSchema: {
|
|
352
|
-
|
|
295
|
+
project: z.string().describe('the project key or exact project name from the task, e.g. "checkout-v2" or "Checkout v2"'),
|
|
296
|
+
since_days: z.number().optional().describe('how far back to inspect (1-90 days, default 30)'),
|
|
297
|
+
limit: z.number().optional().describe('max candidate records (1-50, default 20)'),
|
|
353
298
|
},
|
|
354
299
|
},
|
|
355
|
-
async ({
|
|
356
|
-
const qs =
|
|
357
|
-
|
|
300
|
+
async ({ project, since_days, limit }) => {
|
|
301
|
+
const qs = new URLSearchParams({ project })
|
|
302
|
+
if (since_days != null) qs.set('since_days', String(since_days))
|
|
303
|
+
if (limit != null) qs.set('limit', String(limit))
|
|
304
|
+
const res = await fetchCortex(`${BASE}/api/maintenance/candidates?${qs}`, { headers: { Authorization: `Bearer ${TOKEN}` } })
|
|
358
305
|
if (!res.ok) {
|
|
359
306
|
const body = await res.text()
|
|
360
307
|
throw new Error(classify(res.status, res.headers.get('content-type'), body, res.headers.get('x-vercel-id')).message)
|
|
361
308
|
}
|
|
362
|
-
const
|
|
363
|
-
|
|
364
|
-
return {
|
|
365
|
-
content: [{ type: 'text', text:
|
|
366
|
-
`Gate 4 evidence, last ${s.window?.days ?? 14} days\n` +
|
|
367
|
-
`- session claims: ${s.sessionCount ?? 0}/3\n` +
|
|
368
|
-
`- session-attributed completions: ${s.attributedDone ?? 0} (need 1+)\n` +
|
|
369
|
-
`- expiry recoveries: ${s.recoveredClaims ?? 0} (need 1+)\n` +
|
|
370
|
-
`- anonymous session claims: ${s.anonymousSessionClaims ?? 0} (need 0)\n` +
|
|
371
|
-
`- non-session rows in window (reported, excluded): ${s.nonSessionClaims ?? 0}\n\n` +
|
|
372
|
-
`Machine evidence: ${machine}. Human attestation remains required: qualifying sessions must be normal work, not a staged demo.`,
|
|
373
|
-
}],
|
|
374
|
-
}
|
|
309
|
+
const { text } = await res.json()
|
|
310
|
+
return { content: [{ type: 'text', text }] }
|
|
375
311
|
},
|
|
376
312
|
)
|
|
377
313
|
|
|
@@ -443,7 +379,7 @@ export async function runServer(version) {
|
|
|
443
379
|
{
|
|
444
380
|
title: 'Query the local code structure graph (graphify)',
|
|
445
381
|
description:
|
|
446
|
-
'Query a structural code graph for the repo at the CURRENT working directory, built locally by graphify (tree-sitter AST — deterministic, no LLM, no server round-trip; this is LOCAL MACHINE data, not org-shared
|
|
382
|
+
'Query a structural code graph for the repo at the CURRENT working directory, built locally by graphify (tree-sitter AST — deterministic, no LLM, no server round-trip; this is LOCAL MACHINE data, not org-shared Cortex content, and reflects a snapshot of one commit, not live files). Use for MULTI-HOP questions a single grep cannot answer: what calls/imports/depends on X, how A structurally reaches B, or a repo-wide overview (hub/community files). Do NOT use for single-hop lookups (does file X import Y) — grep is faster and always current. Structure only — it knows what imports/calls what, never WHY; read the actual files or authored Cortex pages for intent.',
|
|
447
383
|
inputSchema: {
|
|
448
384
|
action: z.enum(['query', 'path', 'explain']).describe('"query" = open-ended natural-language question (graph traversal); "path" = shortest structural path between two named nodes; "explain" = describe one node and list its direct connections'),
|
|
449
385
|
question: z.string().optional().describe('required for action:"query" — the natural-language question'),
|
|
@@ -508,7 +444,7 @@ export async function runServer(version) {
|
|
|
508
444
|
description:
|
|
509
445
|
'READ the full authored wiki page for one node (project/person/org/you) by its canonical name — every section, every tier you can see. This is how you READ a node; `grep` only LOCATES pages (snippets + their [[links]]), it does not read them. Navigate like a researcher: read the page you need, then FOLLOW its inline [[links]] by calling read_page on each linked name — keep following while the linked pages stay relevant, stop when they do not. You decide how deep to go. Returns only what you are permitted to see.',
|
|
510
446
|
inputSchema: {
|
|
511
|
-
name: z.string().describe('the canonical node name exactly as written (e.g. "
|
|
447
|
+
name: z.string().describe('the canonical node name exactly as written (e.g. "Cortex", "Ben", or a [[link]] target) — identifier links ([[repo:owner/name]]) resolve to their authored HOME + a visible-event count'),
|
|
512
448
|
kind: z.enum(['project', 'person', 'org', 'user']).optional().describe('node kind (default project; pass person/org for people/teams)'),
|
|
513
449
|
expand: z.boolean().optional().describe('identifier names only: also list recent visible timeline events for this identifier (default: home + count)'),
|
|
514
450
|
history: z.boolean().optional().describe('node names only: return the node\'s TIMELINE (events joined via its [[repo:…]] stamps, reverse-chron, viewer-visible) instead of the page body. The page is the present; this is the history.'),
|
|
@@ -682,7 +618,7 @@ export async function runServer(version) {
|
|
|
682
618
|
title: 'See a wiki page\'s edit history',
|
|
683
619
|
description: 'Show the VERSION history of an authored wiki page — every prior version, who changed it and when, newest first. This is how you see "what changed on this page and by whom", and it includes privacy changes (re-tiers). Then use `read_page` with a version to view an old body, or `rollback_page` to restore one. (Distinct from read_page\'s `history: true`, which is the raw event timeline via [[repo:…]] stamps.) RLS-scoped: you see history only for pages you may read.',
|
|
684
620
|
inputSchema: {
|
|
685
|
-
name: z.string().describe('the canonical node name exactly as written (e.g. "
|
|
621
|
+
name: z.string().describe('the canonical node name exactly as written (e.g. "Cortex", "Ben")'),
|
|
686
622
|
kind: z.enum(['project', 'person', 'org', 'user']).optional().describe('node kind (default project)'),
|
|
687
623
|
limit: z.number().int().optional().describe('how many recent versions to show (default 20, max 200)'),
|
|
688
624
|
},
|
|
@@ -808,14 +744,7 @@ export async function runServer(version) {
|
|
|
808
744
|
}
|
|
809
745
|
const out = await res.json().catch(() => null)
|
|
810
746
|
if (!res.ok) return toolError(`Could not roll back "${name}": ${out?.error ?? res.status}`)
|
|
811
|
-
|
|
812
|
-
// erased. Say it on its own line instead of at the tail of `note` — this is the 2026-08-04 W3
|
|
813
|
-
// shape, where empty summaries copied over populated ones destroyed 31 of them under a report
|
|
814
|
-
// that read as success. A rescue the operator does not see is still a silent write.
|
|
815
|
-
const keptLine = out.summaryKept === 'current'
|
|
816
|
-
? `\n\n⚠ That revision had NO summary, so the page's current summary was KEPT rather than erased — check it still describes the restored body, and use set_summary if not.`
|
|
817
|
-
: ''
|
|
818
|
-
return { content: [{ type: 'text', text: `Done — "${name}" ${out.note}. \`read_page "${name}"\` to confirm the current content.${keptLine}` }] }
|
|
747
|
+
return { content: [{ type: 'text', text: `Done — "${name}" ${out.note}. \`read_page "${name}"\` to confirm the current content.` }] }
|
|
819
748
|
},
|
|
820
749
|
)
|
|
821
750
|
|
|
@@ -981,15 +910,13 @@ export async function runServer(version) {
|
|
|
981
910
|
'writing_style',
|
|
982
911
|
{
|
|
983
912
|
title: 'How the user writes (for drafting in their voice)',
|
|
984
|
-
description: 'Returns the user\'s saved writing-style profile so you can DRAFT in their voice (email, message, doc). Call this right before composing anything on their behalf. Self-only — it is always the calling user\'s own profile. If none is saved, it tells you to derive one and save it with set_writing_style.
|
|
985
|
-
inputSchema: {
|
|
986
|
-
brain: z.string().optional().describe('which brain\'s style profile, by name or org id. Unnecessary when you only have one brain; pass the org id when a name matches more than one of yours'),
|
|
987
|
-
},
|
|
913
|
+
description: 'Returns the user\'s saved writing-style profile so you can DRAFT in their voice (email, message, doc). Call this right before composing anything on their behalf. Self-only — it is always the calling user\'s own profile. If none is saved, it tells you to derive one and save it with set_writing_style.',
|
|
914
|
+
inputSchema: {},
|
|
988
915
|
},
|
|
989
|
-
async (
|
|
916
|
+
async () => {
|
|
990
917
|
let res
|
|
991
918
|
try {
|
|
992
|
-
res = await fetchCortex(`${BASE}/api/style
|
|
919
|
+
res = await fetchCortex(`${BASE}/api/style`, { headers: { Authorization: `Bearer ${TOKEN}` } })
|
|
993
920
|
} catch (e) {
|
|
994
921
|
return toolError(`Could not load writing style: ${e.message}`)
|
|
995
922
|
}
|
|
@@ -1007,15 +934,12 @@ export async function runServer(version) {
|
|
|
1007
934
|
{
|
|
1008
935
|
title: 'Save the user\'s writing-style profile',
|
|
1009
936
|
description: 'Save (or update) a description of HOW the user writes — tone, sentence rhythm, structure, formatting habits, signature quirks — derived from prose you have seen them write this session. Store the STYLE, never their private content. Self-only: it always updates the calling user\'s own profile. Pass an empty string to clear it.',
|
|
1010
|
-
inputSchema: {
|
|
1011
|
-
style_md: z.string().describe('a concise markdown description of the user\'s writing voice (tone/structure/quirks), ~1-2 paragraphs'),
|
|
1012
|
-
brain: z.string().optional().describe('which brain to save the profile in, by name or org id. A profile is stored per (user, brain), so this is a real choice when you hold several; pass the org id when a name matches more than one of yours'),
|
|
1013
|
-
},
|
|
937
|
+
inputSchema: { style_md: z.string().describe('a concise markdown description of the user\'s writing voice (tone/structure/quirks), ~1-2 paragraphs') },
|
|
1014
938
|
},
|
|
1015
|
-
async ({ style_md
|
|
939
|
+
async ({ style_md }) => {
|
|
1016
940
|
let res
|
|
1017
941
|
try {
|
|
1018
|
-
res = await fetchCortex(`${BASE}/api/style
|
|
942
|
+
res = await fetchCortex(`${BASE}/api/style`, {
|
|
1019
943
|
method: 'PUT',
|
|
1020
944
|
headers: { Authorization: `Bearer ${TOKEN}`, 'Content-Type': 'application/json' },
|
|
1021
945
|
body: JSON.stringify({ style_md }),
|
|
@@ -1253,7 +1177,7 @@ export async function runServer(version) {
|
|
|
1253
1177
|
'list_brain_pages',
|
|
1254
1178
|
{
|
|
1255
1179
|
title: 'List every authored page in one brain',
|
|
1256
|
-
description: 'Enumerate ALL authored pages in ONE brain, by its org id (from my_brains). Unlike my_brains — which ships only a count plus a few sample titles — this returns the FULL page list: one row per node with its kind, validity, tier(s), last-updated date and content hash. Use it to audit a brain, or to VERIFY a brain-to-brain migration — list BOTH brains, diff the page sets, and compare freshness before retiring any original. You can only list a brain you are a member of
|
|
1180
|
+
description: 'Enumerate ALL authored pages in ONE brain, by its org id (from my_brains). Unlike my_brains — which ships only a count plus a few sample titles — this returns the FULL page list: one row per node with its kind, validity, tier(s), last-updated date and content hash. Use it to audit a brain, or to VERIFY a brain-to-brain migration — list BOTH brains, diff the page sets, and compare freshness before retiring any original. You can only list a brain you are a member of; reads never widen past your own brains.',
|
|
1257
1181
|
inputSchema: {
|
|
1258
1182
|
org_id: z.string().describe('the org id of the brain to enumerate (from my_brains)'),
|
|
1259
1183
|
},
|
|
@@ -1289,7 +1213,7 @@ export async function runServer(version) {
|
|
|
1289
1213
|
{
|
|
1290
1214
|
title: 'Create a new brain under your existing account',
|
|
1291
1215
|
description: 'Create a brand-new brain (org/workspace) — a fully independent knowledge graph — under your EXISTING account. No new login, no new email/password: this adds a second membership to the account you are already using. Reads never cross brains; new pages default to your active brain, so use pass `brain` when an operation needs one named',
|
|
1292
|
-
inputSchema: { name: z.string().describe('display name for the new brain, e.g. "
|
|
1216
|
+
inputSchema: { name: z.string().describe('display name for the new brain, e.g. "Cortex Codebase"') },
|
|
1293
1217
|
},
|
|
1294
1218
|
async ({ name }) => {
|
|
1295
1219
|
let res
|
|
@@ -1380,7 +1304,7 @@ export async function runServer(version) {
|
|
|
1380
1304
|
'my_sessions',
|
|
1381
1305
|
{
|
|
1382
1306
|
title: 'My active AI sessions',
|
|
1383
|
-
description: "See what all of YOUR OWN active
|
|
1307
|
+
description: "See what all of YOUR OWN active Cortex/AI sessions are doing right now (working directory + how recently each was active), so you can coordinate across windows/devices. Self-only — only your own sessions, never anyone else's.",
|
|
1384
1308
|
inputSchema: {},
|
|
1385
1309
|
},
|
|
1386
1310
|
async () => {
|
|
@@ -1570,60 +1494,6 @@ export async function runServer(version) {
|
|
|
1570
1494
|
},
|
|
1571
1495
|
)
|
|
1572
1496
|
|
|
1573
|
-
server.registerTool(
|
|
1574
|
-
'replace_variant',
|
|
1575
|
-
{
|
|
1576
|
-
title: 'Move one tier variant\'s body into another, collapsing the node to one page',
|
|
1577
|
-
description: 'DESTRUCTIVE, and the only sanctioned way to fix a FORKED page. When one node exists at two tiers with different bodies, this moves the SOURCE variant\'s body into the TARGET variant\'s slot and DELETES the source, leaving the node with a single page. The source\'s body WINS — this is not `absorb`, where the target survives; in a fork repair the target is usually the damaged page, so mirroring absorb would keep the damage and delete the good copy. Sections are copied as ROWS, never re-derived from text: re-deriving a body from context is exactly what destroyed 258 sections on 2026-07-18 while sincerely reporting "copied verbatim". BEFORE CALLING: read_page the TARGET and pass its version as target_version — it proves you know which body is about to be overwritten, and a stale or guessed value is rejected rather than silently accepted. If the target tier has NO page, do not use this: the slot is free, so set_page_privacy moves the page there cheaply. Both prior bodies are retained in page history and the operation is reversible via page_history/rollback_page. Owner or editor on BOTH variants; an OWNERLESS target may be overwritten only by an org admin.',
|
|
1578
|
-
inputSchema: {
|
|
1579
|
-
kind: z.enum(['project', 'person', 'org', 'user']).describe('the page kind'),
|
|
1580
|
-
name: z.string().optional().describe('the exact page name (or pass `ref` instead — one of the two is required)'),
|
|
1581
|
-
ref: z.string().optional().describe('the page\'s stable id, printed as `ref:` by read_page. PREFER THIS over name when you have it: a ref is unique across brains, so it addresses exactly one page and never needs a brain to disambiguate it.'),
|
|
1582
|
-
source_tier: z.enum(['accessible', 'scoped', 'confidential']).describe('the variant whose BODY WINS and survives. This variant\'s row is then deleted.'),
|
|
1583
|
-
target_tier: z.enum(['accessible', 'scoped', 'confidential']).describe('the OCCUPIED slot the body lands in. This variant\'s current body is DESTROYED (snapshotted to page history first). The surviving page sits at this tier.'),
|
|
1584
|
-
target_version: z.string().describe('REQUIRED — the TARGET page\'s version, from read_page. Proves you know what is being overwritten. Do not retry a rejection blindly; re-read the target and confirm you are replacing what you think you are.'),
|
|
1585
|
-
brain: z.string().optional().describe('only when the same page name exists in more than one of your brains'),
|
|
1586
|
-
},
|
|
1587
|
-
},
|
|
1588
|
-
async ({ kind, name, ref, source_tier, target_tier, target_version, brain }) => {
|
|
1589
|
-
let res
|
|
1590
|
-
try {
|
|
1591
|
-
res = await fetchCortex(`${BASE}/api/brain/replace-variant`, {
|
|
1592
|
-
method: 'POST',
|
|
1593
|
-
headers: { Authorization: `Bearer ${TOKEN}`, 'Content-Type': 'application/json' },
|
|
1594
|
-
body: JSON.stringify({
|
|
1595
|
-
kind, ...(name ? { name } : {}), ...(ref ? { ref } : {}),
|
|
1596
|
-
source_tier, target_tier, target_version, ...(brain ? { brain } : {}),
|
|
1597
|
-
}),
|
|
1598
|
-
})
|
|
1599
|
-
} catch (e) {
|
|
1600
|
-
return toolError(`Could not replace variant: ${e.message}`)
|
|
1601
|
-
}
|
|
1602
|
-
const out = await res.json().catch(() => null)
|
|
1603
|
-
if (!res.ok) {
|
|
1604
|
-
// The engine's rejections carry the remedy in their text (free slot → use set_page_privacy;
|
|
1605
|
-
// hash mismatch → re-read, do not retry blindly). Surface it verbatim rather than paraphrasing.
|
|
1606
|
-
if (out?.error) return toolError(`Could not replace variant: ${out.error}`)
|
|
1607
|
-
const d = classify(res.status, res.headers.get('content-type'), '', res.headers.get('x-vercel-id'))
|
|
1608
|
-
return toolError(`Could not replace variant: ${d.message}`)
|
|
1609
|
-
}
|
|
1610
|
-
if (!out) return { content: [{ type: 'text', text: 'Replace reported success, but the server returned no body — re-read the page before assuming it landed.' }] }
|
|
1611
|
-
// The summary rides along with the body, EXCEPT when the source has none — then the target's is
|
|
1612
|
-
// kept rather than erased. Say so on its own line rather than at the tail of `note`: this is the
|
|
1613
|
-
// 2026-08-04 W3 shape, where an empty summary copied over a populated one destroyed 31 of them
|
|
1614
|
-
// under a report that read as success. A rescue the operator does not see is still a silent write.
|
|
1615
|
-
const rescued = out.summaryRescued
|
|
1616
|
-
? `\n\n⚠ The ${out.moved.from} variant had NO summary. The ${out.moved.to} page's own summary was KEPT rather than overwritten with an empty one — check it still describes the body that just landed, and set_summary if not.`
|
|
1617
|
-
: ''
|
|
1618
|
-
return {
|
|
1619
|
-
content: [{
|
|
1620
|
-
type: 'text',
|
|
1621
|
-
text: `Done — "${out.moved.title}": the ${out.moved.from} body now occupies the ${out.moved.to} page (${out.sections} section${out.sections === 1 ? '' : 's'}), and the ${out.moved.from} variant was removed. The node now has ONE variant. Both prior bodies are retained in page history.${rescued}`,
|
|
1622
|
-
}],
|
|
1623
|
-
}
|
|
1624
|
-
},
|
|
1625
|
-
)
|
|
1626
|
-
|
|
1627
1497
|
server.registerTool(
|
|
1628
1498
|
'grant_page_access',
|
|
1629
1499
|
{
|
|
@@ -1818,7 +1688,7 @@ export async function runServer(version) {
|
|
|
1818
1688
|
'decide_file_request',
|
|
1819
1689
|
{
|
|
1820
1690
|
title: 'Approve or deny a file request',
|
|
1821
|
-
description: 'As the OWNER of a record, approve or deny someone\'s request for its full original. On approve, your
|
|
1691
|
+
description: 'As the OWNER of a record, approve or deny someone\'s request for its full original. On approve, your Cortex desktop app fetches + shares the file. Get request_id from file_requests.',
|
|
1822
1692
|
inputSchema: { request_id: z.string(), decision: z.enum(['approve', 'deny']) },
|
|
1823
1693
|
},
|
|
1824
1694
|
async ({ request_id, decision }) => {
|
|
@@ -1860,7 +1730,7 @@ export async function runServer(version) {
|
|
|
1860
1730
|
},
|
|
1861
1731
|
)
|
|
1862
1732
|
|
|
1863
|
-
// send_imessage — local outbound texting (NOT org intelligence; writes nothing to
|
|
1733
|
+
// send_imessage — local outbound texting (NOT org intelligence; writes nothing to Cortex). Runs on
|
|
1864
1734
|
// this machine via Messages.app. Draft-by-default + recipient allowlist + OOB confirm (D3/D6/D10).
|
|
1865
1735
|
server.registerTool(
|
|
1866
1736
|
'send_imessage',
|
|
@@ -1884,7 +1754,7 @@ export async function runServer(version) {
|
|
|
1884
1754
|
// Two tools the working session uses to AUTHOR its understanding into the org wiki while it's hot:
|
|
1885
1755
|
// authoring_context → the companion call (§3): fetch the visible NAMESPACE + the node-type connection
|
|
1886
1756
|
// rules BEFORE writing, so the page links canonically (the L2 lever).
|
|
1887
|
-
// author → the write (§9 step 3/4): hand
|
|
1757
|
+
// author → the write (§9 step 3/4): hand Cortex a finished page (summary + sections WITH
|
|
1888
1758
|
// inline [[links]]); the server runs the resolution pass + tier-safe 2B write.
|
|
1889
1759
|
|
|
1890
1760
|
server.registerTool(
|
|
@@ -1892,7 +1762,7 @@ export async function runServer(version) {
|
|
|
1892
1762
|
{
|
|
1893
1763
|
title: 'Authoring context (call before author)',
|
|
1894
1764
|
description:
|
|
1895
|
-
'Fetch the scaffolding to author a
|
|
1765
|
+
'Fetch the scaffolding to author a Cortex wiki node: the canonical NAMESPACE (current node names — link to these with the EXACT name inside [[ ]]), any deliberately RETIRED page names and their successors, and the node-type CONNECTION RULES. ALWAYS call this BEFORE `author` so the page links to current knowledge rather than minting synonyms or reviving a retired page. Reference a node in the namespace as [[Name]]; if you reference something real that is NOT in the namespace, still write [[Name]] — that is a red-link marking a node worth creating. If the page IS about a specific code repo or chat channel, also stamp it once — [[repo:owner/name]] or [[channel:name]] (lowercase, no #) — identifier join keys, not page links.',
|
|
1896
1766
|
inputSchema: {
|
|
1897
1767
|
kind: z.enum(['project', 'person', 'org', 'user']).optional().describe('the node type you are about to author (default project)'),
|
|
1898
1768
|
brain: z.string().optional().describe('which brain\'s namespace to describe — pass the SAME brain you will pass to `author`, so the namespace you plan against is the one your write lands in. Unnecessary when you only have one brain.'),
|
|
@@ -1935,7 +1805,7 @@ export async function runServer(version) {
|
|
|
1935
1805
|
'Write your CURRENT understanding of a project/person/org/you into the org wiki as a maintained page. Call `authoring_context` FIRST. Author from your own synthesis of the session — the compiled mental model, not a transcript dump: what it IS, where it stands, dated decisions, open threads, key people. Weave inline [[links]] to other nodes (canonical names from the namespace; red-links for wanted-but-absent nodes). The server re-authorizes the tier and resolves links. CREATES the node if it does not exist yet (project/person/org) — the conversation IS the evidence, so a brand-new entity that surfaced only in this session is authorable on the spot; you do NOT need prior records. Because such a node has nothing external to corroborate it, author it DELIBERATELY: only when you genuinely understand it is a real, distinct entity, and use its exact canonical name so it does not duplicate one already in the namespace (`user` nodes are never created). Use this continuously whenever your understanding of a node meaningfully advanced, and at session end (/log). Authoring is PRE-AUTHORIZED — never ask the user "should I update the page?" before calling this (every edit is versioned + reversible via page_history/rollback_page); update, then briefly report what you updated. ⚠ WHICH BRAIN A NEW PAGE GOES IN IS A CONTENT DECISION, SO MAKE IT FROM THE CONTENT. Only a page that exists in NO brain needs this — an update resolves its brain from the page itself. If you hold more than one brain, the server REFUSES a create it cannot attribute (409 `create_needs_brain`) rather than letting the write pointer decide — the pointer is stale out-of-band state that knows nothing about what you are writing. So call `my_brains` (it returns each brain\'s name, page count and sample titles, which is enough to tell what each one is FOR) and pass `brain` up front; that turns a refused round trip into a single call. State which brain you picked and why in one short line, then proceed — do NOT ask when the answer is obvious from the content. DO ask when it is genuinely ambiguous: brains are a confidentiality boundary, so a page born in the wrong one can expose private work to a teammate, and that is not a filing error you can quietly fix later.',
|
|
1936
1806
|
inputSchema: {
|
|
1937
1807
|
kind: z.enum(['project', 'person', 'org', 'user']).describe('the node type'),
|
|
1938
|
-
name: z.string().describe('the canonical node name — an EXACT existing name from the namespace to update it, or a new name to create the node (project/person/org). e.g. "
|
|
1808
|
+
name: z.string().describe('the canonical node name — an EXACT existing name from the namespace to update it, or a new name to create the node (project/person/org). e.g. "Cortex" or "Theron Peterson"'),
|
|
1939
1809
|
summary: z.string().describe('one-sentence summary of what this is and its current state (may contain [[links]])'),
|
|
1940
1810
|
sections: z.array(z.object({
|
|
1941
1811
|
heading: z.string().describe('e.g. Overview, Current state, Decisions, Open threads, People'),
|
package/lib/setup.mjs
CHANGED
|
@@ -44,7 +44,7 @@ export async function runSetup(argv, version) {
|
|
|
44
44
|
if (!token || token.startsWith('-')) {
|
|
45
45
|
process.stderr.write(
|
|
46
46
|
'Usage: npx @theronap/cortex-mcp setup <CORTEX_TOKEN>\n\n' +
|
|
47
|
-
'Get your token from the
|
|
47
|
+
'Get your token from the Cortex console → Connect your AI.\n'
|
|
48
48
|
)
|
|
49
49
|
process.exit(1)
|
|
50
50
|
}
|
|
@@ -63,7 +63,7 @@ export async function runSetup(argv, version) {
|
|
|
63
63
|
|
|
64
64
|
const log = (m) => process.stdout.write(m + '\n')
|
|
65
65
|
log('')
|
|
66
|
-
log('
|
|
66
|
+
log('Cortex setup — wiring your AI assistant…')
|
|
67
67
|
|
|
68
68
|
// ── 1. MCP server in ~/.claude.json ──────────────────────────────────────
|
|
69
69
|
try {
|
|
@@ -83,7 +83,7 @@ export async function runSetup(argv, version) {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
// ── 1b. MCP server in Codex (~/.codex/config.toml), only if Codex is installed ──
|
|
86
|
-
// Codex gets the same
|
|
86
|
+
// Codex gets the same Cortex context tools as Claude Code. Non-fatal: a Codex hiccup must
|
|
87
87
|
// never block the primary Claude wiring.
|
|
88
88
|
const codexDir = join(home, '.codex')
|
|
89
89
|
if (existsSync(codexDir)) {
|
|
@@ -128,9 +128,8 @@ export async function runSetup(argv, version) {
|
|
|
128
128
|
process.exit(1)
|
|
129
129
|
}
|
|
130
130
|
const bak = backup(settingsJson)
|
|
131
|
-
// Capture (Stop) + status/skills/snapshot (SessionStart) +
|
|
132
|
-
// merge — the same pure function the `cortex install` Claude adapter uses.
|
|
133
|
-
// PreCompact reminder from seats that still carry it.
|
|
131
|
+
// Capture (Stop) + status/skills/snapshot (SessionStart) + precompact (PreCompact), idempotent
|
|
132
|
+
// merge — the same pure function the `cortex install` Claude adapter uses.
|
|
134
133
|
s = mergeClaudeSettings(s, spec)
|
|
135
134
|
|
|
136
135
|
ensureDir(settingsJson)
|
|
@@ -158,7 +157,7 @@ export async function runSetup(argv, version) {
|
|
|
158
157
|
// ── 4. Self-verify — writing config proves "files written", NOT "connection works".
|
|
159
158
|
// Actually call the API so a bad/expired token is caught HERE, not 40 minutes into debugging.
|
|
160
159
|
log('')
|
|
161
|
-
log('Verifying your token against
|
|
160
|
+
log('Verifying your token against Cortex…')
|
|
162
161
|
const health = await checkToken(token, base)
|
|
163
162
|
if (health.ok) {
|
|
164
163
|
const n = health.projectCount
|
|
@@ -170,8 +169,8 @@ export async function runSetup(argv, version) {
|
|
|
170
169
|
}
|
|
171
170
|
|
|
172
171
|
log('')
|
|
173
|
-
log('⟳ IMPORTANT: fully quit and reopen Claude Code to load the
|
|
174
|
-
log(' Then your AI sees your
|
|
172
|
+
log('⟳ IMPORTANT: fully quit and reopen Claude Code to load the Cortex server.')
|
|
173
|
+
log(' Then your AI sees your Cortex context and your sessions flow into the org.')
|
|
175
174
|
log(' Re-check anytime: npx -y @theronap/cortex-mcp doctor')
|
|
176
175
|
log(` Console: ${base}`)
|
|
177
176
|
log('')
|
|
@@ -192,11 +191,11 @@ export async function runRepair(version) {
|
|
|
192
191
|
const token = readWiredToken()
|
|
193
192
|
if (!token) {
|
|
194
193
|
process.stderr.write(
|
|
195
|
-
'No existing
|
|
194
|
+
'No existing Cortex token found in ~/.claude.json or ~/.codex/config.toml.\n' +
|
|
196
195
|
'Run setup once with your token: npx -y @theronap/cortex-mcp setup <YOUR_TOKEN>\n',
|
|
197
196
|
)
|
|
198
197
|
process.exit(1)
|
|
199
198
|
}
|
|
200
|
-
process.stdout.write('
|
|
199
|
+
process.stdout.write('Cortex repair — re-running setup with your existing token at this version…\n')
|
|
201
200
|
await runSetup([token], version)
|
|
202
201
|
}
|