@theronap/agnoclast-mcp 0.9.282 โ†’ 0.9.284

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.
@@ -181,3 +181,15 @@ export function lockStateLine({ lockedInto = null, lock = null, brains = [] } =
181
181
  return `๐Ÿ”’ Confidential (a session works in one of these ALONE): ${names}\n` +
182
182
  ' This session is NOT locked yet. Pass the name as `brain` to any tool to lock the session to it; using any other brain first locks these away from the session instead.'
183
183
  }
184
+
185
+ const NOT_FOUND_RE = /^(No authored page named|No matches for|No page named|No records? (found|match))/m
186
+
187
+ /**
188
+ * In a locked-in session, a "not found" only means not found IN the confidential brain โ€” a page can exist in a brain
189
+ * the lock hides, and the ordinary not-found text suggests authoring it (Theron's test, 2026-10-29: "author a new page"
190
+ * for a meal plan that sat in Personal). Returns the warning to put FIRST in such a result, or null.
191
+ */
192
+ export function lockedNotFoundNote(text, lockedInto) {
193
+ if (!lockedInto || !NOT_FOUND_RE.test(String(text ?? ''))) return null
194
+ return `โš  Not found in "${lockedInto}" โ€” and only there. This session is locked to that confidential brain, so it cannot see your other brains; what you asked for may exist in one of them. Do NOT author a page here to stand in for it. To reach other brains, start a new session.`
195
+ }
@@ -1,7 +1,8 @@
1
1
  // The names this package is published under, and how to derive each variant's package.json.
2
2
  //
3
- // โš  SUPERSEDED by ADR-0102 (2026-10-29): `cortex-mcp` is retired after 0.9.282, its last dual release,
4
- // which rewrites every machine to the new name on start. The rest of this note is the ADR-0033 ยง3 history.
3
+ // โš  SUPERSEDED by ADR-0102 (2026-10-29): `cortex-mcp` is RETIRED (see RETIRED_TARGETS). 0.9.283 was its last
4
+ // release; that build rewrites every machine to the new name on start. The rest of this note is the ADR-0033 ยง3
5
+ // history, kept because VARIANT_FIELDS and the bin rule still govern any future second name.
5
6
  //
6
7
  // ADR-0033 ยง3. Phase B publishes the SAME build under two names: `@theronap/agnoclast-mcp` going
7
8
  // forward, and `@theronap/cortex-mcp` in perpetuity, because the old name is hardcoded in hook
@@ -21,10 +22,17 @@
21
22
  /** The fields that may legitimately differ between variants. Anything else differing is a bug. */
22
23
  export const VARIANT_FIELDS = ['name', 'bin']
23
24
 
24
- /** Publish targets, primary first. Additive only: a name that has ever been published stays here. */
25
+ /** Publish targets, primary first. */
25
26
  export const PUBLISH_TARGETS = [
26
27
  { name: '@theronap/agnoclast-mcp', bin: 'agnoclast-mcp', role: 'primary' },
27
- { name: '@theronap/cortex-mcp', bin: 'cortex-mcp', role: 'alias' },
28
+ ]
29
+
30
+ /** Names this package USED to publish under, and the last version each received. Never publish to these
31
+ * again: a retired name's @stable/@latest are frozen on a build that moves the machine to the new name
32
+ * (ADR-0102), and a newer release there would be one nobody can migrate away from. Deprecated, never
33
+ * unpublished, so anything pinned to them still installs. */
34
+ export const RETIRED_TARGETS = [
35
+ { name: '@theronap/cortex-mcp', bin: 'cortex-mcp', lastVersion: '0.9.283', retired: '2026-10-29', adr: 'ADR-0102' },
28
36
  ]
29
37
 
30
38
  /** The entry point every variant's bin points at. One file, many names. */
@@ -0,0 +1,62 @@
1
+ // THE SESSION LOG, for an AI outside Claude Code. Pure โ€” see rolling_log.test.mjs.
2
+ //
3
+ // Most AI hosts have no session-end event, so a log written "at close" never happens (Theron, 2026-10-31). The
4
+ // server writes the log itself from the reasons on the session's page edits (web/lib/engine/session_work_log.ts),
5
+ // which costs no model call. An extra turn is the real cost of asking an AI for a log, because that turn re-reads
6
+ // its whole context ("I'm worried about costs, speed, and efficiency"). So this asks only when the reasons leave a
7
+ // gap, at most once per stretch of work, and never in Claude Code, where the capture hook logs the session.
8
+ // The ask rides on a tool result: the one channel every host shares.
9
+ //
10
+ // โš  NOT IN THE CLAUDE.AI CONNECTOR. Anthropic's directory policy forbids a connector that stores conversation
11
+ // history (web/lib/mcp/tools.ts), so this lives only here. See ADR-0106.
12
+
13
+ const IDLE_NEW_SESSION_MS = 4 * 60 * 60 * 1000
14
+ const WEAK_EDITS_BEFORE_ASKING = 2
15
+ const WEAK_REASON_CHARS = 15
16
+ const MAX_NOTES_CHARS = 8000
17
+
18
+ const PAGE_EDIT_TOOLS = new Set(['author', 'edit_page', 'merge_sections', 'rename_page', 'rename_section'])
19
+
20
+ export function newRollingLog(baseKey, hostNamesSession) {
21
+ return { baseKey, hostNamesSession, generation: 0, sessionId: baseKey, lastCallAt: null, weakEdits: 0, asked: false, notes: [] }
22
+ }
23
+
24
+ /**
25
+ * Called before each tool runs. A long-lived agent's process outlives its work, so a long silence starts a new
26
+ * session; otherwise one record would keep being replaced for weeks. Returns the new id when it rotated.
27
+ */
28
+ export function rotateIfIdle(s, now) {
29
+ const idle = s.lastCallAt !== null && now - s.lastCallAt >= IDLE_NEW_SESSION_MS
30
+ s.lastCallAt = now
31
+ if (!idle || s.hostNamesSession) return null
32
+ s.generation += 1
33
+ s.sessionId = `${s.baseKey}-${s.generation}`
34
+ s.weakEdits = 0
35
+ s.asked = false
36
+ s.notes = []
37
+ return s.sessionId
38
+ }
39
+
40
+ /** A page edit whose reason says too little for the server to build a log from. */
41
+ export function noteWork(s, tool, args) {
42
+ if (!PAGE_EDIT_TOOLS.has(tool)) return
43
+ if (String(args?.reason ?? '').trim().length < WEAK_REASON_CHARS) s.weakEdits += 1
44
+ }
45
+
46
+ export function noteLogged(s, summary) {
47
+ s.weakEdits = 0
48
+ if (!s.hostNamesSession && summary) s.notes.push(summary)
49
+ }
50
+
51
+ /** An AI sends only what is new, so a log costs the same on the tenth call as on the first. */
52
+ export function withEarlierNotes(s, summary) {
53
+ if (s.hostNamesSession) return summary
54
+ return [...s.notes, summary].join('\n\n').slice(-MAX_NOTES_CHARS)
55
+ }
56
+
57
+ /** The line to add to this tool result, or ''. */
58
+ export function reminderLine(s) {
59
+ if (s.hostNamesSession || s.asked || s.weakEdits < WEAK_EDITS_BEFORE_ASKING) return ''
60
+ s.asked = true
61
+ return `๐Ÿ“ ${s.weakEdits} page edits here have reasons too short to explain the work. Add one or two sentences with log_session saying what is new (name the brain if the person has several). Skip it for trivial or personal work.`
62
+ }
package/lib/server.mjs CHANGED
@@ -12,7 +12,8 @@ import { folderClaimLine } from './folder_claims.mjs'
12
12
  import { renderFolderClaimOffers, renderIdentifierResolution, renderUnroutedPathStamps } from './identifier_routes.mjs'
13
13
  import { renderDeclines, renderFolderDecisionsApplied, renderFolderQuestions } from './folder_decisions.mjs'
14
14
  import { resolveSessionKey, resolveLogSessionId } from './session_key.mjs'
15
- import { aiAccountOf, confidentialBrainNamed, fetchMyConfidential, gatherAgentProof, lockStateLine, markLockedIn, requestSeatToken } from './confidential_session.mjs'
15
+ import { newRollingLog, rotateIfIdle, noteWork, noteLogged, reminderLine, withEarlierNotes } from './rolling_log.mjs'
16
+ import { aiAccountOf, confidentialBrainNamed, fetchMyConfidential, gatherAgentProof, lockStateLine, lockedNotFoundNote, markLockedIn, requestSeatToken } from './confidential_session.mjs'
16
17
  import { runSendImessage } from './imessage_send.mjs'
17
18
  import { formatGrepHits } from './grep_cli.mjs'
18
19
  import { buildProposal, renderProposal, withAskNotice } from './propose_obligation.mjs'
@@ -291,6 +292,7 @@ export async function runServer(version) {
291
292
  // resolve THIS session's brain pointer. Must be set BEFORE the first fetchCortex call below โ€”
292
293
  // otherwise the opening requests of a session would silently resolve by the account pointer.
293
294
  setSessionKey(SESSION_KEY)
295
+ const rolling = newRollingLog(SESSION_KEY, !!process.env.CLAUDE_CODE_SESSION_ID)
294
296
 
295
297
  // โ”€โ”€ CONFIDENTIAL BRAINS: THE FIRST-TOUCH LOCK (Theron, 2026-10-28) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
296
298
  // Only for a person who holds a confidential seat; for everyone else `confidential.brains` is empty and nothing
@@ -511,10 +513,25 @@ export async function runServer(version) {
511
513
  const check = await lockedAnswerFor(BASE, TOKEN, name, takesArgs ? args[0] : {}, fetchCortex)
512
514
  if (!check.run) return { content: [{ type: 'text', text: check.text }] }
513
515
  }
516
+ const startedAt = Date.now()
517
+ const rotated = rotateIfIdle(rolling, startedAt)
518
+ // The header stamps page revisions, so a new id here keeps a log joined to the pages it wrote.
519
+ if (rotated) setSessionKey(rotated)
514
520
  const result = await handler(...args)
521
+ if (!result?.isError) {
522
+ if (name === 'log_session') {
523
+ if (result?.content?.[0]?.text?.startsWith('Logged')) noteLogged(rolling, takesArgs ? args[0]?.summary : null)
524
+ } else {
525
+ noteWork(rolling, name, takesArgs ? args[0] : null)
526
+ const remind = !lockedInto && reminderLine(rolling)
527
+ if (remind && Array.isArray(result?.content)) result.content = [...result.content, { type: 'text', text: remind }]
528
+ }
529
+ }
515
530
  // Locked in: every result says so (Theron, 2026-10-28), so an AI never mistakes which state the session is in.
516
531
  if (lockedInto && Array.isArray(result?.content)) {
517
- return { ...result, content: [...result.content, { type: 'text', text: lockStateLine({ lockedInto }) }] }
532
+ const text = result.content.map((c) => (c?.type === 'text' ? c.text : '')).join('\n')
533
+ const warn = lockedNotFoundNote(text, lockedInto)
534
+ return { ...result, content: [...(warn ? [{ type: 'text', text: warn }] : []), ...result.content, { type: 'text', text: lockStateLine({ lockedInto }) }] }
518
535
  }
519
536
  return result
520
537
  }))
@@ -717,7 +734,7 @@ function renderNudge(payload) {
717
734
  'log_session',
718
735
  {
719
736
  title: 'Log this session to Agnoclast',
720
- description: 'Persist a CURATED summary of this work session as its durable Agnoclast record (authoritative โ€” supersedes the auto-capture hook). Call at session close after composing the summary. `sessionId` now defaults to this session automatically (from CLAUDE_CODE_SESSION_ID) so the log dedupes with the auto-capture of the same session โ€” pass it explicitly only to log on behalf of a DIFFERENT session, e.g. recovering one whose own close-out failed. If you belong to more than one brain you MUST name one โ€” without a brain a session log has no route and is STAGED rather than recorded. **If the session touched work belonging to different brains, pass `segments` instead of `summary` and split it** โ€” one segment per brain, each summary standing on its own and never alluding to the others. Reports every segment individually; a partial result is reported as PARTIAL, never as success.',
737
+ description: 'Persist a CURATED summary of this work session as its durable Agnoclast record (authoritative โ€” supersedes the auto-capture hook). Call after meaningful work and at session close: each call replaces the earlier log for this session. Outside Claude Code, send only what is new: earlier notes are kept for you. `sessionId` now defaults to this session automatically (from CLAUDE_CODE_SESSION_ID) so the log dedupes with the auto-capture of the same session โ€” pass it explicitly only to log on behalf of a DIFFERENT session, e.g. recovering one whose own close-out failed. If you belong to more than one brain you MUST name one โ€” without a brain a session log has no route and is STAGED rather than recorded. **If the session touched work belonging to different brains, pass `segments` instead of `summary` and split it** โ€” one segment per brain, each summary standing on its own and never alluding to the others. Reports every segment individually; a partial result is reported as PARTIAL, never as success.',
721
738
  inputSchema: {
722
739
  summary: z.string().optional().describe('the curated session summary โ€” the single-brain form. Omit when passing `segments`'),
723
740
  segments: z.array(z.object({
@@ -759,7 +776,12 @@ function renderNudge(payload) {
759
776
  // confident-looking join that is silently wrong. A missing id is honest; an invented one is not.
760
777
  // Hosts that do not set the var keep today's timestamp behaviour. Negative-controlled in
761
778
  // session_key.test.mjs.
762
- sessionId = resolveLogSessionId(sessionId, process.env)
779
+ //
780
+ // โš  A host with no conversation id logs under this process's rolling id. That is not the invented value
781
+ // warned about above: every write this process made carries it as x-cortex-session-key, so it joins to
782
+ // the pages those writes touched. See rolling_log.mjs.
783
+ sessionId = resolveLogSessionId(sessionId, process.env) ?? rolling.sessionId
784
+ if (summary) summary = withEarlierNotes(rolling, summary)
763
785
  // A session is a container of TIME, not a topic (ADR-0029 step 4). Normalize to a list of
764
786
  // segments; the single-brain call is just a one-segment list.
765
787
  const list = Array.isArray(segments) && segments.length
@@ -9,7 +9,9 @@
9
9
  // with no session_write_pointers row of its own. Any other MCP host that doesn't set the var gets
10
10
  // today's unchanged per-process-random behavior.
11
11
  export function resolveSessionKey(env, randomUUID) {
12
- return env.CLAUDE_CODE_SESSION_ID || randomUUID()
12
+ // The `agent-` prefix is how the server knows no capture hook will log this session, so it writes the
13
+ // log itself from the session's page edits (lib/engine/session_work_log.ts).
14
+ return env.CLAUDE_CODE_SESSION_ID || `agent-${randomUUID()}`
13
15
  }
14
16
 
15
17
  // Which session id a `log_session` call should RECORD. Pure โ€” see session_key.test.mjs.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theronap/agnoclast-mcp",
3
- "version": "0.9.282",
3
+ "version": "0.9.284",
4
4
  "description": "Connect your AI assistant to Cortex โ€” your org's projects, activity, gaps, and directives, scoped to you.",
5
5
  "type": "module",
6
6
  "bin": {