@theronap/cortex-mcp 0.9.78 → 0.9.79
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 +51 -139
- 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/use_brain.mjs +0 -82
package/lib/server.mjs
CHANGED
|
@@ -40,7 +40,7 @@ async function redLinkTriage(BASE, TOKEN, name) {
|
|
|
40
40
|
// file-request tools, and a module-level `fail` would be silently shadowed by it from that point on.
|
|
41
41
|
const toolError = (text) => ({ content: [{ type: 'text', text }], isError: true })
|
|
42
42
|
|
|
43
|
-
// The
|
|
43
|
+
// The Cortex MCP server (stdio). Serves the signed-in employee's scoped org
|
|
44
44
|
// context to their AI assistant. CORTEX_TOKEN identifies the user + org.
|
|
45
45
|
|
|
46
46
|
export async function runServer(version) {
|
|
@@ -48,7 +48,7 @@ export async function runServer(version) {
|
|
|
48
48
|
const BASE = resolveBase(process.env.CORTEX_URL)
|
|
49
49
|
|
|
50
50
|
if (!TOKEN) {
|
|
51
|
-
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')
|
|
52
52
|
process.exit(1)
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -90,7 +90,7 @@ export async function runServer(version) {
|
|
|
90
90
|
const now = Date.now()
|
|
91
91
|
if (cache && now - cache.ts < 5 * 60 * 1000) return cache.text
|
|
92
92
|
// fetchCortex retries transient infra/5xx; classify turns a failure into an honest message
|
|
93
|
-
// (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".
|
|
94
94
|
const res = await fetchCortex(`${BASE}/api/mcp-context`, { headers: { Authorization: `Bearer ${TOKEN}` } })
|
|
95
95
|
if (!res.ok) {
|
|
96
96
|
const body = await res.text()
|
|
@@ -117,7 +117,7 @@ export async function runServer(version) {
|
|
|
117
117
|
server.registerTool(
|
|
118
118
|
'my_context',
|
|
119
119
|
{
|
|
120
|
-
title: 'My
|
|
120
|
+
title: 'My Cortex context',
|
|
121
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.',
|
|
122
122
|
inputSchema: { question: z.string().optional().describe('optional opening user question to center the context around') },
|
|
123
123
|
},
|
|
@@ -137,53 +137,6 @@ export async function runServer(version) {
|
|
|
137
137
|
},
|
|
138
138
|
)
|
|
139
139
|
|
|
140
|
-
// Where this machine's unattended session captures land. The server half shipped 2026-08-09 with no
|
|
141
|
-
// client surface at all, so the only way to set it was a hand-written authenticated HTTP call —
|
|
142
|
-
// which meant three real users whose sessions were silently being held could not fix it themselves.
|
|
143
|
-
// This is the surface that makes it answerable in conversation: "put my sessions in TTO".
|
|
144
|
-
server.registerTool(
|
|
145
|
-
'set_capture_brain',
|
|
146
|
-
{
|
|
147
|
-
title: 'Choose where your session captures are saved',
|
|
148
|
-
description:
|
|
149
|
-
'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.',
|
|
150
|
-
inputSchema: {
|
|
151
|
-
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.'),
|
|
152
|
-
},
|
|
153
|
-
},
|
|
154
|
-
async ({ brain }) => {
|
|
155
|
-
const url = `${BASE}/api/brain/capture-default`
|
|
156
|
-
if (!brain?.trim()) {
|
|
157
|
-
const res = await fetchCortex(url, { headers: { Authorization: `Bearer ${TOKEN}` } })
|
|
158
|
-
if (!res.ok) {
|
|
159
|
-
const body = await res.text()
|
|
160
|
-
throw new Error(classify(res.status, res.headers.get('content-type'), body, res.headers.get('x-vercel-id')).message)
|
|
161
|
-
}
|
|
162
|
-
const { defaults } = await res.json()
|
|
163
|
-
if (!defaults?.length) {
|
|
164
|
-
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.' }] }
|
|
165
|
-
}
|
|
166
|
-
const lines = defaults.map((d) => `${d.sourceType} captures land in "${d.orgName}" (${d.orgId}), set ${String(d.updatedAt).slice(0, 10)}`)
|
|
167
|
-
return { content: [{ type: 'text', text: lines.join('\n') }] }
|
|
168
|
-
}
|
|
169
|
-
const res = await fetchCortex(url, {
|
|
170
|
-
method: 'POST',
|
|
171
|
-
headers: { Authorization: `Bearer ${TOKEN}`, 'Content-Type': 'application/json' },
|
|
172
|
-
body: JSON.stringify({ sourceType: 'claude-code', brain: brain.trim() }),
|
|
173
|
-
})
|
|
174
|
-
const body = await res.text()
|
|
175
|
-
if (!res.ok) {
|
|
176
|
-
// Prefer the server's own error: a 409 lists the org ids of an ambiguous name, which IS the
|
|
177
|
-
// remedy, and a generic classification would throw that away.
|
|
178
|
-
let msg
|
|
179
|
-
try { msg = JSON.parse(body).error } catch { /* fall through to the classified message */ }
|
|
180
|
-
throw new Error(msg ?? classify(res.status, res.headers.get('content-type'), body, res.headers.get('x-vercel-id')).message)
|
|
181
|
-
}
|
|
182
|
-
const j = JSON.parse(body)
|
|
183
|
-
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.` }] }
|
|
184
|
-
},
|
|
185
|
-
)
|
|
186
|
-
|
|
187
140
|
// T8: cortex-log's authoritative writer. The skill composes a curated summary, then calls this to
|
|
188
141
|
// persist it AS the durable record (capture_source='skill'). The ingest conflict guard ensures the
|
|
189
142
|
// auto-capture hook never clobbers it. Pass the SAME sessionId the hook uses so the two dedupe onto
|
|
@@ -191,8 +144,8 @@ export async function runServer(version) {
|
|
|
191
144
|
server.registerTool(
|
|
192
145
|
'log_session',
|
|
193
146
|
{
|
|
194
|
-
title: 'Log this session to
|
|
195
|
-
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.',
|
|
196
149
|
inputSchema: {
|
|
197
150
|
summary: z.string().describe('the curated session summary (what was done, decided, left open) — becomes the durable record'),
|
|
198
151
|
project: z.string().optional().describe('project key/name this session worked in'),
|
|
@@ -219,7 +172,7 @@ export async function runServer(version) {
|
|
|
219
172
|
throw new Error(classify(res.status, res.headers.get('content-type'), body, res.headers.get('x-vercel-id')).message)
|
|
220
173
|
}
|
|
221
174
|
const j = await res.json().catch(() => ({}))
|
|
222
|
-
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'}.` }] }
|
|
223
176
|
},
|
|
224
177
|
)
|
|
225
178
|
|
|
@@ -333,6 +286,31 @@ export async function runServer(version) {
|
|
|
333
286
|
},
|
|
334
287
|
)
|
|
335
288
|
|
|
289
|
+
server.registerTool(
|
|
290
|
+
'maintenance_candidates',
|
|
291
|
+
{
|
|
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.',
|
|
294
|
+
inputSchema: {
|
|
295
|
+
project: z.string().describe('the project key from the task, e.g. "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)'),
|
|
298
|
+
},
|
|
299
|
+
},
|
|
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}` } })
|
|
305
|
+
if (!res.ok) {
|
|
306
|
+
const body = await res.text()
|
|
307
|
+
throw new Error(classify(res.status, res.headers.get('content-type'), body, res.headers.get('x-vercel-id')).message)
|
|
308
|
+
}
|
|
309
|
+
const { text } = await res.json()
|
|
310
|
+
return { content: [{ type: 'text', text }] }
|
|
311
|
+
},
|
|
312
|
+
)
|
|
313
|
+
|
|
336
314
|
server.registerTool(
|
|
337
315
|
'search_org',
|
|
338
316
|
{
|
|
@@ -401,7 +379,7 @@ export async function runServer(version) {
|
|
|
401
379
|
{
|
|
402
380
|
title: 'Query the local code structure graph (graphify)',
|
|
403
381
|
description:
|
|
404
|
-
'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.',
|
|
405
383
|
inputSchema: {
|
|
406
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'),
|
|
407
385
|
question: z.string().optional().describe('required for action:"query" — the natural-language question'),
|
|
@@ -466,7 +444,7 @@ export async function runServer(version) {
|
|
|
466
444
|
description:
|
|
467
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.',
|
|
468
446
|
inputSchema: {
|
|
469
|
-
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'),
|
|
470
448
|
kind: z.enum(['project', 'person', 'org', 'user']).optional().describe('node kind (default project; pass person/org for people/teams)'),
|
|
471
449
|
expand: z.boolean().optional().describe('identifier names only: also list recent visible timeline events for this identifier (default: home + count)'),
|
|
472
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.'),
|
|
@@ -640,7 +618,7 @@ export async function runServer(version) {
|
|
|
640
618
|
title: 'See a wiki page\'s edit history',
|
|
641
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.',
|
|
642
620
|
inputSchema: {
|
|
643
|
-
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")'),
|
|
644
622
|
kind: z.enum(['project', 'person', 'org', 'user']).optional().describe('node kind (default project)'),
|
|
645
623
|
limit: z.number().int().optional().describe('how many recent versions to show (default 20, max 200)'),
|
|
646
624
|
},
|
|
@@ -766,14 +744,7 @@ export async function runServer(version) {
|
|
|
766
744
|
}
|
|
767
745
|
const out = await res.json().catch(() => null)
|
|
768
746
|
if (!res.ok) return toolError(`Could not roll back "${name}": ${out?.error ?? res.status}`)
|
|
769
|
-
|
|
770
|
-
// erased. Say it on its own line instead of at the tail of `note` — this is the 2026-08-04 W3
|
|
771
|
-
// shape, where empty summaries copied over populated ones destroyed 31 of them under a report
|
|
772
|
-
// that read as success. A rescue the operator does not see is still a silent write.
|
|
773
|
-
const keptLine = out.summaryKept === 'current'
|
|
774
|
-
? `\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.`
|
|
775
|
-
: ''
|
|
776
|
-
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.` }] }
|
|
777
748
|
},
|
|
778
749
|
)
|
|
779
750
|
|
|
@@ -939,15 +910,13 @@ export async function runServer(version) {
|
|
|
939
910
|
'writing_style',
|
|
940
911
|
{
|
|
941
912
|
title: 'How the user writes (for drafting in their voice)',
|
|
942
|
-
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.
|
|
943
|
-
inputSchema: {
|
|
944
|
-
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'),
|
|
945
|
-
},
|
|
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: {},
|
|
946
915
|
},
|
|
947
|
-
async (
|
|
916
|
+
async () => {
|
|
948
917
|
let res
|
|
949
918
|
try {
|
|
950
|
-
res = await fetchCortex(`${BASE}/api/style
|
|
919
|
+
res = await fetchCortex(`${BASE}/api/style`, { headers: { Authorization: `Bearer ${TOKEN}` } })
|
|
951
920
|
} catch (e) {
|
|
952
921
|
return toolError(`Could not load writing style: ${e.message}`)
|
|
953
922
|
}
|
|
@@ -965,15 +934,12 @@ export async function runServer(version) {
|
|
|
965
934
|
{
|
|
966
935
|
title: 'Save the user\'s writing-style profile',
|
|
967
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.',
|
|
968
|
-
inputSchema: {
|
|
969
|
-
style_md: z.string().describe('a concise markdown description of the user\'s writing voice (tone/structure/quirks), ~1-2 paragraphs'),
|
|
970
|
-
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'),
|
|
971
|
-
},
|
|
937
|
+
inputSchema: { style_md: z.string().describe('a concise markdown description of the user\'s writing voice (tone/structure/quirks), ~1-2 paragraphs') },
|
|
972
938
|
},
|
|
973
|
-
async ({ style_md
|
|
939
|
+
async ({ style_md }) => {
|
|
974
940
|
let res
|
|
975
941
|
try {
|
|
976
|
-
res = await fetchCortex(`${BASE}/api/style
|
|
942
|
+
res = await fetchCortex(`${BASE}/api/style`, {
|
|
977
943
|
method: 'PUT',
|
|
978
944
|
headers: { Authorization: `Bearer ${TOKEN}`, 'Content-Type': 'application/json' },
|
|
979
945
|
body: JSON.stringify({ style_md }),
|
|
@@ -1211,7 +1177,7 @@ export async function runServer(version) {
|
|
|
1211
1177
|
'list_brain_pages',
|
|
1212
1178
|
{
|
|
1213
1179
|
title: 'List every authored page in one brain',
|
|
1214
|
-
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.',
|
|
1215
1181
|
inputSchema: {
|
|
1216
1182
|
org_id: z.string().describe('the org id of the brain to enumerate (from my_brains)'),
|
|
1217
1183
|
},
|
|
@@ -1247,7 +1213,7 @@ export async function runServer(version) {
|
|
|
1247
1213
|
{
|
|
1248
1214
|
title: 'Create a new brain under your existing account',
|
|
1249
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',
|
|
1250
|
-
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"') },
|
|
1251
1217
|
},
|
|
1252
1218
|
async ({ name }) => {
|
|
1253
1219
|
let res
|
|
@@ -1338,7 +1304,7 @@ export async function runServer(version) {
|
|
|
1338
1304
|
'my_sessions',
|
|
1339
1305
|
{
|
|
1340
1306
|
title: 'My active AI sessions',
|
|
1341
|
-
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.",
|
|
1342
1308
|
inputSchema: {},
|
|
1343
1309
|
},
|
|
1344
1310
|
async () => {
|
|
@@ -1528,60 +1494,6 @@ export async function runServer(version) {
|
|
|
1528
1494
|
},
|
|
1529
1495
|
)
|
|
1530
1496
|
|
|
1531
|
-
server.registerTool(
|
|
1532
|
-
'replace_variant',
|
|
1533
|
-
{
|
|
1534
|
-
title: 'Move one tier variant\'s body into another, collapsing the node to one page',
|
|
1535
|
-
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.',
|
|
1536
|
-
inputSchema: {
|
|
1537
|
-
kind: z.enum(['project', 'person', 'org', 'user']).describe('the page kind'),
|
|
1538
|
-
name: z.string().optional().describe('the exact page name (or pass `ref` instead — one of the two is required)'),
|
|
1539
|
-
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.'),
|
|
1540
|
-
source_tier: z.enum(['accessible', 'scoped', 'confidential']).describe('the variant whose BODY WINS and survives. This variant\'s row is then deleted.'),
|
|
1541
|
-
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.'),
|
|
1542
|
-
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.'),
|
|
1543
|
-
brain: z.string().optional().describe('only when the same page name exists in more than one of your brains'),
|
|
1544
|
-
},
|
|
1545
|
-
},
|
|
1546
|
-
async ({ kind, name, ref, source_tier, target_tier, target_version, brain }) => {
|
|
1547
|
-
let res
|
|
1548
|
-
try {
|
|
1549
|
-
res = await fetchCortex(`${BASE}/api/brain/replace-variant`, {
|
|
1550
|
-
method: 'POST',
|
|
1551
|
-
headers: { Authorization: `Bearer ${TOKEN}`, 'Content-Type': 'application/json' },
|
|
1552
|
-
body: JSON.stringify({
|
|
1553
|
-
kind, ...(name ? { name } : {}), ...(ref ? { ref } : {}),
|
|
1554
|
-
source_tier, target_tier, target_version, ...(brain ? { brain } : {}),
|
|
1555
|
-
}),
|
|
1556
|
-
})
|
|
1557
|
-
} catch (e) {
|
|
1558
|
-
return toolError(`Could not replace variant: ${e.message}`)
|
|
1559
|
-
}
|
|
1560
|
-
const out = await res.json().catch(() => null)
|
|
1561
|
-
if (!res.ok) {
|
|
1562
|
-
// The engine's rejections carry the remedy in their text (free slot → use set_page_privacy;
|
|
1563
|
-
// hash mismatch → re-read, do not retry blindly). Surface it verbatim rather than paraphrasing.
|
|
1564
|
-
if (out?.error) return toolError(`Could not replace variant: ${out.error}`)
|
|
1565
|
-
const d = classify(res.status, res.headers.get('content-type'), '', res.headers.get('x-vercel-id'))
|
|
1566
|
-
return toolError(`Could not replace variant: ${d.message}`)
|
|
1567
|
-
}
|
|
1568
|
-
if (!out) return { content: [{ type: 'text', text: 'Replace reported success, but the server returned no body — re-read the page before assuming it landed.' }] }
|
|
1569
|
-
// The summary rides along with the body, EXCEPT when the source has none — then the target's is
|
|
1570
|
-
// kept rather than erased. Say so on its own line rather than at the tail of `note`: this is the
|
|
1571
|
-
// 2026-08-04 W3 shape, where an empty summary copied over a populated one destroyed 31 of them
|
|
1572
|
-
// under a report that read as success. A rescue the operator does not see is still a silent write.
|
|
1573
|
-
const rescued = out.summaryRescued
|
|
1574
|
-
? `\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.`
|
|
1575
|
-
: ''
|
|
1576
|
-
return {
|
|
1577
|
-
content: [{
|
|
1578
|
-
type: 'text',
|
|
1579
|
-
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}`,
|
|
1580
|
-
}],
|
|
1581
|
-
}
|
|
1582
|
-
},
|
|
1583
|
-
)
|
|
1584
|
-
|
|
1585
1497
|
server.registerTool(
|
|
1586
1498
|
'grant_page_access',
|
|
1587
1499
|
{
|
|
@@ -1776,7 +1688,7 @@ export async function runServer(version) {
|
|
|
1776
1688
|
'decide_file_request',
|
|
1777
1689
|
{
|
|
1778
1690
|
title: 'Approve or deny a file request',
|
|
1779
|
-
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.',
|
|
1780
1692
|
inputSchema: { request_id: z.string(), decision: z.enum(['approve', 'deny']) },
|
|
1781
1693
|
},
|
|
1782
1694
|
async ({ request_id, decision }) => {
|
|
@@ -1818,7 +1730,7 @@ export async function runServer(version) {
|
|
|
1818
1730
|
},
|
|
1819
1731
|
)
|
|
1820
1732
|
|
|
1821
|
-
// 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
|
|
1822
1734
|
// this machine via Messages.app. Draft-by-default + recipient allowlist + OOB confirm (D3/D6/D10).
|
|
1823
1735
|
server.registerTool(
|
|
1824
1736
|
'send_imessage',
|
|
@@ -1842,7 +1754,7 @@ export async function runServer(version) {
|
|
|
1842
1754
|
// Two tools the working session uses to AUTHOR its understanding into the org wiki while it's hot:
|
|
1843
1755
|
// authoring_context → the companion call (§3): fetch the visible NAMESPACE + the node-type connection
|
|
1844
1756
|
// rules BEFORE writing, so the page links canonically (the L2 lever).
|
|
1845
|
-
// author → the write (§9 step 3/4): hand
|
|
1757
|
+
// author → the write (§9 step 3/4): hand Cortex a finished page (summary + sections WITH
|
|
1846
1758
|
// inline [[links]]); the server runs the resolution pass + tier-safe 2B write.
|
|
1847
1759
|
|
|
1848
1760
|
server.registerTool(
|
|
@@ -1850,7 +1762,7 @@ export async function runServer(version) {
|
|
|
1850
1762
|
{
|
|
1851
1763
|
title: 'Authoring context (call before author)',
|
|
1852
1764
|
description:
|
|
1853
|
-
'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.',
|
|
1854
1766
|
inputSchema: {
|
|
1855
1767
|
kind: z.enum(['project', 'person', 'org', 'user']).optional().describe('the node type you are about to author (default project)'),
|
|
1856
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.'),
|
|
@@ -1893,7 +1805,7 @@ export async function runServer(version) {
|
|
|
1893
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.',
|
|
1894
1806
|
inputSchema: {
|
|
1895
1807
|
kind: z.enum(['project', 'person', 'org', 'user']).describe('the node type'),
|
|
1896
|
-
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"'),
|
|
1897
1809
|
summary: z.string().describe('one-sentence summary of what this is and its current state (may contain [[links]])'),
|
|
1898
1810
|
sections: z.array(z.object({
|
|
1899
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
|
}
|
package/lib/skills.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { homedir } from 'os'
|
|
|
3
3
|
import { join, dirname } from 'path'
|
|
4
4
|
import { fileURLToPath } from 'url'
|
|
5
5
|
|
|
6
|
-
// Managed
|
|
6
|
+
// Managed Cortex skills.
|
|
7
7
|
//
|
|
8
8
|
// Two sources, one install pipeline:
|
|
9
9
|
// 1. BUNDLED — shipped inside this package (cortex-log, cortex-context, cortex-author-docs).
|
|
@@ -155,42 +155,21 @@ export function installSkills(opts = {}) {
|
|
|
155
155
|
|
|
156
156
|
if (quiet && (summary.installed.length || summary.repaired.length)) {
|
|
157
157
|
// SessionStart surfaces one line in Claude Code so a silent self-heal isn't invisible.
|
|
158
|
-
process.stdout.write(`
|
|
158
|
+
process.stdout.write(`Cortex: synced managed skill(s) into ${summary.targets.join(' + ')}.\n`)
|
|
159
159
|
}
|
|
160
160
|
return summary
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
// Decide what to install from a served org-skill list: drop invalid names
|
|
164
|
-
// (bundled wins — core skills are inalterable)
|
|
165
|
-
// unit-testable without a network.
|
|
163
|
+
// Decide what to install from a served org-skill list: drop invalid names and bundled collisions
|
|
164
|
+
// (bundled wins — core skills are inalterable). Pure, so it's unit-testable without a network.
|
|
166
165
|
export function planOrgInstall(served, bundledNames) {
|
|
167
166
|
const bundled = new Set(bundledNames)
|
|
168
167
|
const install = []
|
|
169
168
|
const skipped = []
|
|
170
|
-
|
|
171
|
-
// /api/skills now fans out across EVERY brain the caller belongs to (ADR-0022 acrossMyBrains), so
|
|
172
|
-
// for the first time two brains can serve the SAME skill name. Installing both would write one
|
|
173
|
-
// file twice and silently leave whichever landed last — an executable body from a brain the user
|
|
174
|
-
// never chose. There is no principled winner, so a cross-brain collision installs NEITHER and says
|
|
175
|
-
// so, matching how a bundled collision already resolves: when in doubt, do not install.
|
|
176
|
-
const byName = new Map()
|
|
177
|
-
for (const s of served ?? []) {
|
|
178
|
-
const n = (s?.name ?? '').trim()
|
|
179
|
-
if (!byName.has(n)) byName.set(n, [])
|
|
180
|
-
byName.get(n).push(s)
|
|
181
|
-
}
|
|
182
|
-
|
|
183
169
|
for (const s of served ?? []) {
|
|
184
170
|
const name = (s?.name ?? '').trim()
|
|
185
171
|
if (!NAME_RE.test(name) || typeof s?.body_md !== 'string' || !s.body_md.trim()) { skipped.push({ name: name || '(unnamed)', why: 'invalid' }); continue }
|
|
186
172
|
if (bundled.has(name)) { skipped.push({ name, why: 'collides with a bundled core skill' }); continue }
|
|
187
|
-
const dupes = byName.get(name) ?? []
|
|
188
|
-
if (dupes.length > 1) {
|
|
189
|
-
// Name the brains so the owner knows which to rename. `brain` is the tag acrossMyBrains adds.
|
|
190
|
-
const brains = [...new Set(dupes.map((d) => d?.brain).filter(Boolean))]
|
|
191
|
-
skipped.push({ name, why: `published by ${dupes.length} brains (${brains.join(', ') || 'unknown'}) — rename one; installing neither` })
|
|
192
|
-
continue
|
|
193
|
-
}
|
|
194
173
|
install.push({ name, source: s.body_md })
|
|
195
174
|
}
|
|
196
175
|
return { install, skipped }
|
|
@@ -222,13 +201,6 @@ export async function syncOrgSkills(opts = {}) {
|
|
|
222
201
|
if (res.ok) {
|
|
223
202
|
served = (await res.json())?.skills ?? []
|
|
224
203
|
summary.source = 'server'
|
|
225
|
-
} else {
|
|
226
|
-
// ⚠ DO NOT MAKE THIS SILENT AGAIN. `if (res.ok)` alone is how a 100% failure hid for weeks:
|
|
227
|
-
// /api/skills answered 409 to every multi-brain caller, this fell through to the cache below,
|
|
228
|
-
// and the only log line ('unreachable and no cache') does NOT print when a cache exists. So
|
|
229
|
-
// org skills silently stopped updating and nothing anywhere said so. Fail-soft is right —
|
|
230
|
-
// SessionStart must not break — but fail-soft is not fail-quiet.
|
|
231
|
-
log(` · org skills: server said ${res.status} — using last-good cache. Run \`doctor\` if this persists.`)
|
|
232
204
|
}
|
|
233
205
|
} catch { /* fall through to cache */ }
|
|
234
206
|
if (!served && Array.isArray(cache?.skills)) { served = cache.skills; summary.source = 'cache' }
|
|
@@ -258,72 +230,29 @@ export async function syncOrgSkills(opts = {}) {
|
|
|
258
230
|
const bits = []
|
|
259
231
|
if (changed.length) bits.push(`synced ${changed.join(', ')}`)
|
|
260
232
|
if (summary.removed.length) bits.push(`removed ${summary.removed.join(', ')}`)
|
|
261
|
-
process.stdout.write(`
|
|
233
|
+
process.stdout.write(`Cortex: org skills — ${bits.join('; ')}${summary.source === 'cache' ? ' (offline cache)' : ''}.\n`)
|
|
262
234
|
} else if (!quiet) {
|
|
263
235
|
log(` ✓ org skills up to date (${currentNames.length} published${skipped.length ? `, ${skipped.length} skipped` : ''})`)
|
|
264
236
|
}
|
|
265
237
|
return summary
|
|
266
238
|
}
|
|
267
239
|
|
|
268
|
-
//
|
|
269
|
-
//
|
|
270
|
-
|
|
271
|
-
// existed as `body.error ?? HTTP ${status}`, which printed the bare code `brain_required` and threw
|
|
272
|
-
// all of that away — the user saw a two-word error with no notion of what a brain is, which ones they
|
|
273
|
-
// have, or what to type next. Pure + exported so the shape is unit-testable without a network.
|
|
274
|
-
export function renderPushError(body, status) {
|
|
275
|
-
const lines = [body?.message ?? body?.error ?? `HTTP ${status}`]
|
|
276
|
-
const brains = Array.isArray(body?.brains) ? body.brains : []
|
|
277
|
-
if (brains.length) {
|
|
278
|
-
lines.push('', ' Your brains:')
|
|
279
|
-
for (const b of brains) {
|
|
280
|
-
const pages = typeof b?.pageCount === 'number' ? ` — ${b.pageCount} page${b.pageCount === 1 ? '' : 's'}` : ''
|
|
281
|
-
const titles = Array.isArray(b?.sampleTitles) && b.sampleTitles.length
|
|
282
|
-
? `: ${b.sampleTitles.slice(0, 2).join('; ')}` : ''
|
|
283
|
-
lines.push(` ${b?.name ?? b?.orgId ?? '(unnamed)'}${pages}${titles}`)
|
|
284
|
-
}
|
|
285
|
-
lines.push('', ' Re-run with --brain "<name>".')
|
|
286
|
-
}
|
|
287
|
-
return lines.join('\n')
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
// `skills push <file> [--brain <name>]` / `skills push --disable <name> [--brain <name>]` /
|
|
291
|
-
// `skills push --enable <name> [--brain <name>]` — publish or toggle an org skill
|
|
292
|
-
// (owner/manager/admin; the server enforces the role).
|
|
293
|
-
//
|
|
294
|
-
// ⚠ --brain IS NOT OPTIONAL FOR A MULTI-BRAIN CALLER, and until 2026-08-08 there was no way to pass
|
|
295
|
-
// it. Publishing MODIFIES one brain, so the server correctly uses ADR-0022's `requireBrain` half and
|
|
296
|
-
// refuses to guess — but this command sent no `brain`, so every push and every --disable from a
|
|
297
|
-
// multi-brain account died on `brain_required` with no way forward. Confirmed against production:
|
|
298
|
-
// `skills push --disable cortex-author-docs` → `✗ brain_required`, full stop.
|
|
299
|
-
//
|
|
300
|
-
// This is the WRITE twin of the GET bug fixed in #467. The read was miscategorised and now fans out;
|
|
301
|
-
// the write was categorised correctly and simply had no input for the answer it demanded.
|
|
302
|
-
export async function runSkillsPush(argv) {
|
|
240
|
+
// `skills push <file>` / `skills push --disable <name>` / `skills push --enable <name>` —
|
|
241
|
+
// publish or toggle an org skill (owner/manager/admin; the server enforces the role).
|
|
242
|
+
async function runSkillsPush(argv) {
|
|
303
243
|
const { resolveBase, readWiredToken, fetchCortex } = await import('./diagnose.mjs')
|
|
304
244
|
const token = process.env.CORTEX_TOKEN || readWiredToken()
|
|
305
|
-
if (!token) { process.stderr.write('No
|
|
245
|
+
if (!token) { process.stderr.write('No Cortex token wired — run setup first.\n'); return 1 }
|
|
306
246
|
const base = resolveBase(process.env.CORTEX_URL)
|
|
307
247
|
|
|
308
|
-
const brainIdx = argv.findIndex((a) => a === '--brain')
|
|
309
|
-
const brain = brainIdx === -1 ? null : argv[brainIdx + 1]
|
|
310
|
-
if (brainIdx !== -1 && (!brain || brain.startsWith('-'))) {
|
|
311
|
-
process.stderr.write('Usage: skills push … --brain <name> (missing brain name)\n')
|
|
312
|
-
return 1
|
|
313
|
-
}
|
|
314
|
-
// Strip --brain AND its value before any positional parsing below. The value does not start with
|
|
315
|
-
// '-', so the `argv.find(a => !a.startsWith('-'))` file lookup would otherwise take it as the
|
|
316
|
-
// SKILL.md path and push the wrong thing.
|
|
317
|
-
const rest = brainIdx === -1 ? argv : argv.filter((_, i) => i !== brainIdx && i !== brainIdx + 1)
|
|
318
|
-
|
|
319
248
|
let payload
|
|
320
|
-
const toggleIdx =
|
|
249
|
+
const toggleIdx = argv.findIndex((a) => a === '--disable' || a === '--enable')
|
|
321
250
|
if (toggleIdx !== -1) {
|
|
322
|
-
const name =
|
|
323
|
-
if (!name) { process.stderr.write(`Usage: skills push ${
|
|
324
|
-
payload = { name, enabled:
|
|
251
|
+
const name = argv[toggleIdx + 1]
|
|
252
|
+
if (!name) { process.stderr.write(`Usage: skills push ${argv[toggleIdx]} <name>\n`); return 1 }
|
|
253
|
+
payload = { name, enabled: argv[toggleIdx] === '--enable' }
|
|
325
254
|
} else {
|
|
326
|
-
const file =
|
|
255
|
+
const file = argv.find((a) => !a.startsWith('-'))
|
|
327
256
|
if (!file || !existsSync(file)) { process.stderr.write('Usage: skills push <SKILL.md> (file not found)\n'); return 1 }
|
|
328
257
|
const body_md = readFileSync(file, 'utf8')
|
|
329
258
|
const name = frontmatterName(body_md, '').toLowerCase()
|
|
@@ -335,14 +264,13 @@ export async function runSkillsPush(argv) {
|
|
|
335
264
|
}
|
|
336
265
|
|
|
337
266
|
try {
|
|
338
|
-
const
|
|
339
|
-
const res = await fetchCortex(`${base}/api/skills${qs}`, {
|
|
267
|
+
const res = await fetchCortex(`${base}/api/skills`, {
|
|
340
268
|
method: 'POST',
|
|
341
269
|
headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
|
|
342
270
|
body: JSON.stringify(payload),
|
|
343
271
|
})
|
|
344
272
|
const body = await res.json().catch(() => ({}))
|
|
345
|
-
if (!res.ok) { process.stderr.write(`✗ ${
|
|
273
|
+
if (!res.ok) { process.stderr.write(`✗ ${body.error ?? `HTTP ${res.status}`}\n`); return 1 }
|
|
346
274
|
process.stdout.write(
|
|
347
275
|
payload.body_md
|
|
348
276
|
? `✓ published "${payload.name}" to your org — every seat installs it on next session start.\n`
|
|
@@ -361,7 +289,7 @@ export async function runSkills(argv = []) {
|
|
|
361
289
|
if (argv[0] === 'push') return runSkillsPush(argv.slice(1))
|
|
362
290
|
|
|
363
291
|
const quiet = argv.includes('--quiet')
|
|
364
|
-
if (!quiet) process.stdout.write('\
|
|
292
|
+
if (!quiet) process.stdout.write('\nCortex skills — installing managed skills…\n')
|
|
365
293
|
const r = installSkills({ quiet })
|
|
366
294
|
if (!quiet) {
|
|
367
295
|
if (!r.targets.length) process.stdout.write(' ! No agent CLI found (~/.claude or ~/.codex). Nothing to install.\n')
|