@theronap/agnoclast-mcp 0.9.175 → 0.9.176
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/bin/cortex-mcp.mjs +27 -0
- package/lib/server.mjs +7 -20
- package/lib/session_key.mjs +24 -0
- package/package.json +1 -1
package/bin/cortex-mcp.mjs
CHANGED
|
@@ -58,6 +58,33 @@ if (process.env.CORTEX_SUMMARIZING && CONTEXT_HOOK_COMMANDS.has(cmd)) {
|
|
|
58
58
|
process.exit(0)
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
// ADR-0020 Stage 2, amended 2026-09-25 — stamp THIS session's identity on the read-only context
|
|
62
|
+
// hooks. Until now setSessionKey was called ONLY in server.mjs, so a one-shot hook sent no
|
|
63
|
+
// x-cortex-session-key header, /api/mcp-context resolved the person-wide pointer, and the settling
|
|
64
|
+
// feed — which is session-scoped by definition — rendered nothing at session start no matter how
|
|
65
|
+
// many arrivals were asking this session to judge them. 269 units sat in the settle window on the
|
|
66
|
+
// day this was found; the block had been silently empty through three separate attempts to fix it
|
|
67
|
+
// further upstream, because every one of them fixed the server while the HOOK stayed anonymous.
|
|
68
|
+
//
|
|
69
|
+
// Placed at the dispatcher for the same reason the guard above is: it is one rule about what a hook
|
|
70
|
+
// process IS, and putting it in four subcommands is how the fifth gets forgotten.
|
|
71
|
+
//
|
|
72
|
+
// env ONLY, deliberately never stdin: arrivals-notice and hydrate consume stdin themselves with
|
|
73
|
+
// readFileSync(0), which DRAINS the pipe. A read here would starve them of their own payload —
|
|
74
|
+
// fixing one notice by breaking another.
|
|
75
|
+
//
|
|
76
|
+
// hookSessionKey never invents a random id (see its note in session_key.mjs): no id -> no header ->
|
|
77
|
+
// exactly the previous behavior, rather than a key that matches nothing and prints a confident
|
|
78
|
+
// "nothing is waiting for you".
|
|
79
|
+
if (CONTEXT_HOOK_COMMANDS.has(cmd)) {
|
|
80
|
+
const { hookSessionKey } = await import('../lib/session_key.mjs')
|
|
81
|
+
const forSession = hookSessionKey(process.env)
|
|
82
|
+
if (forSession) {
|
|
83
|
+
const { setSessionKey } = await import('../lib/diagnose.mjs')
|
|
84
|
+
setSessionKey(forSession)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
61
88
|
if (cmd === '--version' || cmd === '-v') {
|
|
62
89
|
process.stdout.write(`cortex-mcp ${VERSION}\n`)
|
|
63
90
|
process.exit(0)
|
package/lib/server.mjs
CHANGED
|
@@ -231,25 +231,13 @@ export async function runServer(version) {
|
|
|
231
231
|
const body = await res.text()
|
|
232
232
|
throw new Error(classify(res.status, res.headers.get('content-type'), body, res.headers.get('x-vercel-id')).message)
|
|
233
233
|
}
|
|
234
|
-
const { context, brainRefs
|
|
235
|
-
//
|
|
236
|
-
//
|
|
237
|
-
//
|
|
238
|
-
//
|
|
239
|
-
// every request since fetchCortex started sending it. The settling feed is the only inherently
|
|
240
|
-
// SESSION-scoped signal in the block, which is why it was structurally excluded rather than
|
|
241
|
-
// forgotten — and why a NEW SESSION has never once been told which arrivals are asking it a
|
|
242
|
-
// question. That is the resume case: start a session, and the offers are waiting.
|
|
243
|
-
//
|
|
244
|
-
// ⚠ NOT CACHED, and the distinction matters. The block is cached for 5 minutes; an OFFER is
|
|
245
|
-
// live state that another session can claim out from under this one. Baking it into the cached
|
|
246
|
-
// string would serve an offer already taken, or hide one that just arrived — and a feed whose
|
|
247
|
-
// whole contract is "this persists until you answer it" cannot afford to be five minutes wrong.
|
|
248
|
-
// So the cache keeps the person-scoped context exactly as before, and the session-scoped feed is
|
|
249
|
-
// appended only on a FRESH fetch. Session start and resume are always fresh fetches, which is
|
|
250
|
-
// the case this exists for; mid-session cache hits are covered by the tools.
|
|
234
|
+
const { context, brainRefs } = await res.json()
|
|
235
|
+
// ⚠ THE FEED IS RENDERED SERVER-SIDE NOW, inside assembleMcpContext, NOT appended here.
|
|
236
|
+
// Appending client-side only reached the MCP tool path: the session-start block is printed by a
|
|
237
|
+
// CLI subcommand that takes `payload.context` verbatim, and the hooks run `cortex-mcp@stable` —
|
|
238
|
+
// six versions behind. Server-side rendering reaches every client including the pinned one.
|
|
251
239
|
cache = { text: context, ts: now, repo }
|
|
252
|
-
|
|
240
|
+
|
|
253
241
|
// T11: stash the digest node refs surfaced this fetch so capture.mjs can forward them as
|
|
254
242
|
// hydrated_from at the session's ingest (feedback-loop guard). Keyed by cwd so the matching
|
|
255
243
|
// session picks them up. Best-effort + inert when brainRefs is empty (digest flag off).
|
|
@@ -261,8 +249,7 @@ export async function runServer(version) {
|
|
|
261
249
|
writeFileSync(join(dir, `${key}.json`), JSON.stringify({ refs: brainRefs, ts: now }))
|
|
262
250
|
}
|
|
263
251
|
} catch { /* best-effort — never break context serving */ }
|
|
264
|
-
|
|
265
|
-
return withSettling
|
|
252
|
+
return context
|
|
266
253
|
}
|
|
267
254
|
|
|
268
255
|
const server = new McpServer({ name: 'cortex', version })
|
package/lib/session_key.mjs
CHANGED
|
@@ -35,3 +35,27 @@ export function resolveLogSessionId(explicit, env) {
|
|
|
35
35
|
if (typeof fromEnv === 'string' && fromEnv.trim()) return fromEnv.trim()
|
|
36
36
|
return undefined
|
|
37
37
|
}
|
|
38
|
+
|
|
39
|
+
// Which session a one-shot CONTEXT HOOK process is acting FOR. Pure — see session_key.test.mjs.
|
|
40
|
+
//
|
|
41
|
+
// Third session-id question in this file, and like resolveLogSessionId it is deliberately NOT built
|
|
42
|
+
// on resolveSessionKey. That one answers "which session is this process" for the WRITE POINTER, and
|
|
43
|
+
// may invent a randomUUID() because a write pointer is only ever compared to ITSELF — any stable
|
|
44
|
+
// value works.
|
|
45
|
+
//
|
|
46
|
+
// This key is compared to OTHER sessions' keys: the server uses it to decide which settling offers
|
|
47
|
+
// are asking THIS session to judge an arrival. A random value there matches no offer, so the block
|
|
48
|
+
// renders EMPTY rather than absent — "nothing is waiting for you" when 269 units were. An empty
|
|
49
|
+
// queue and an unidentified process MUST NOT look the same, so there is no random fallback here.
|
|
50
|
+
//
|
|
51
|
+
// So: the conversation id Claude Code names, else NOTHING. Never a random.
|
|
52
|
+
//
|
|
53
|
+
// Why a hook has an identity at all, given the ADR-0020 note in diagnose.mjs says these processes
|
|
54
|
+
// "have no session of their own": true, and unchanged for writes. But a SessionStart hook runs ON
|
|
55
|
+
// BEHALF of a session, and CLAUDE_CODE_SESSION_ID names it. Read-only context commands may therefore
|
|
56
|
+
// speak for it; capture and the other writers still fall back to the account pointer as intended.
|
|
57
|
+
export function hookSessionKey(env) {
|
|
58
|
+
const fromEnv = env?.CLAUDE_CODE_SESSION_ID
|
|
59
|
+
if (typeof fromEnv === 'string' && fromEnv.trim()) return fromEnv.trim()
|
|
60
|
+
return null
|
|
61
|
+
}
|
package/package.json
CHANGED