@theronap/agnoclast-mcp 0.9.301 → 0.9.303

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.
@@ -6,8 +6,10 @@
6
6
  // passage can only be replaced by text at least as supported as the session's own log.
7
7
  import { scrub } from './closeout.mjs'
8
8
 
9
- const MAX_PAGES = 12
10
- const SEARCH_HITS = 8
9
+ const MAX_PAGES = 24
10
+ const PAGES_PER_CALL = 5
11
+ const SEARCH_HITS = 12
12
+ const HITS_PER_QUERY = 2
11
13
  const MAX_EDITS = 10
12
14
  const EVIDENCE_WINDOW = 1_500
13
15
  const MAX_EVIDENCE = 60_000
@@ -18,7 +20,21 @@ const MIN_KEPT_RATIO = 0.6
18
20
  export function wikiCandidates(segments, read, found = []) {
19
21
  const named = segments.flatMap((s) => s.pages)
20
22
  const reads = Object.entries(read.pagesRead ?? {}).sort((a, b) => b[1] - a[1]).map(([name]) => name)
21
- return [...new Set([...named, ...read.pages, ...reads.slice(0, 3), ...found])].slice(0, MAX_PAGES)
23
+ // Every page it read, not only the three most read (the 2026-11-03 test missed 8 important edits on pages read once),
24
+ // but search hits before the rest: most pages a manual close-out fixes were never opened before it.
25
+ return [...new Set([...named, ...read.pages, ...reads.slice(0, 3), ...found, ...reads])].slice(0, MAX_PAGES)
26
+ }
27
+
28
+ /**
29
+ * PURE. The heading of the section an anchor sits in, as `edit_page` names it: the last heading line above it, less the
30
+ * one "· as of" stamp `read_page` appends. The model guessed it, and stripped every stamp, so a heading that holds one
31
+ * of its own failed twice on 2026-11-03 ("What this is · as of 2026-10-13").
32
+ */
33
+ export function sectionHeading(text, anchor) {
34
+ const at = text.indexOf(anchor)
35
+ if (at < 0) return null
36
+ const lines = [...text.slice(0, at).matchAll(/^#{1,6} +(.+)$/gm)]
37
+ return lines.length ? lines.at(-1)[1].trim().replace(/ · as of \S+$/, '') : null
22
38
  }
23
39
 
24
40
  /** PURE. What to search for pages the session never opened: each segment's title and each workstream heading in it. */
@@ -27,6 +43,23 @@ export function searchQueries(segments) {
27
43
  return [...new Set([...segments.map((s) => s.title ?? s.summary.slice(0, 80)), ...headings])]
28
44
  }
29
45
 
46
+ /**
47
+ * PURE. Asks for the searches a person closing this session would run. Manual close-outs find most of the pages they
48
+ * fix by grepping pointed phrases ("stale deployment Safari old code skew"); on 2026-11-03, 20 of the 25 pages they
49
+ * edited were never opened before the close, and segment titles found almost none of them.
50
+ */
51
+ export function queryPrompt({ segments, facts }) {
52
+ return `A work session has just closed. Below are its record and fact notes. List the searches you would run over the team wiki to find existing pages this session's work made wrong or out of date: a feature, system, decision, project, bug list, status page or person page it changed.
53
+ Each search is 2 to 6 distinctive words: names, identifiers, feature or file names, PR numbers. No generic words.
54
+ Reply with JSON only: an array of at most 10 strings.
55
+
56
+ SESSION RECORD:
57
+ ${segments.map((s) => s.summary).join('\n\n')}
58
+
59
+ FACT NOTES:
60
+ ${facts.slice(-30_000)}`
61
+ }
62
+
30
63
  /** PURE. Page names in a `grep` reply, best first. */
31
64
  export function parseGrepPages(text) {
32
65
  return [...new Set([...text.matchAll(/^- \[page\] (.+?)(?: > .*)? \[\w+\]$/gm)].map((m) => m[1]))]
@@ -130,13 +163,19 @@ export async function proposeWikiEdits({ segments, read, facts, raw, log = '', c
130
163
  const pages = []
131
164
  // Manual close-outs also fix pages the session never opened, like a package's status page: in the two longest
132
165
  // sessions of the 2026-11-02 test, 17 of 22 such pages. Searching each workstream finds those.
133
- const found = [...new Set((await Promise.all(searchQueries(segments).map(search))).flat())].slice(0, SEARCH_HITS)
166
+ const asked = parseJsonArray(await call(queryPrompt({ segments, facts }), 'haiku')).filter((q) => typeof q === 'string')
167
+ const hits = await Promise.all([...asked, ...searchQueries(segments)].map(search))
168
+ // The best two from each search, so one broad search cannot fill every slot.
169
+ const found = [...new Set(hits.flatMap((h) => h.slice(0, HITS_PER_QUERY)))].slice(0, SEARCH_HITS)
134
170
  for (const name of wikiCandidates(segments, read, found)) {
135
171
  const page = await readPage(name, allowedBrains)
136
172
  if (page) pages.push(page)
137
173
  }
138
174
  if (!pages.length) return { proposed: [], accepted: [], refused: [] }
139
- const proposed = parseJsonArray(await call(proposePrompt({ segments, pages, facts, asOf }), 'sonnet')).slice(0, MAX_EDITS)
175
+ // A few pages per call: one call over all of them stopped at 10 edits where a manual close-out made 31.
176
+ const batches = []
177
+ for (let i = 0; i < pages.length; i += PAGES_PER_CALL) batches.push(pages.slice(i, i + PAGES_PER_CALL))
178
+ const proposed = (await Promise.all(batches.map(async (b) => parseJsonArray(await call(proposePrompt({ segments, pages: b, facts, asOf }), 'sonnet')).slice(0, MAX_EDITS)))).flat()
140
179
  const evidence = `${facts}\n${raw}`
141
180
  const refused = []
142
181
  const passed = []
@@ -148,7 +187,7 @@ export async function proposeWikiEdits({ segments, read, facts, raw, log = '', c
148
187
  if (!passed.length) return { proposed, accepted: [], refused }
149
188
  const keep = new Set(parseJsonArray(await call(verifyPrompt(passed, { raw, facts, log }), 'sonnet')))
150
189
  passed.forEach((e, i) => { if (!keep.has(i)) refused.push({ ...e, why: 'not supported by the log' }) })
151
- return { proposed, accepted: passed.filter((_, i) => keep.has(i)).map((e) => { const p = pages.find((x) => x.name === e.page); return { ...e, version: p.version, brain: p.brain } }), refused }
190
+ return { proposed, accepted: passed.filter((_, i) => keep.has(i)).map((e) => { const p = pages.find((x) => x.name === e.page); return { ...e, heading: sectionHeading(p.text, e.old_string) ?? e.heading, version: p.version, brain: p.brain } }), refused }
152
191
  }
153
192
 
154
193
  /**
@@ -20,8 +20,10 @@
20
20
  // · a document or spreadsheet the session OPENED outside a repo — what the person handed it to work on.
21
21
  // Never: anything under node_modules, .git, ~/.claude, ~/.cortex, temp folders, dotfiles, or over 50 MB.
22
22
  //
23
- // It says nothing when the person has not turned on "Let assistants upload files": the upload would be refused. Its
24
- // words are facts and options marked "Agnoclast note:", like every other note since 0.9.299.
23
+ // It says nothing unless Agnoclast answers that this person's AI may store files: a paid brain plan, the feature on,
24
+ // and "Let assistants upload files" turned on (ADR-0108; /api/stored-files/capture-status). No answer is silence too,
25
+ // so a free account is never prompted. Its words are facts and options marked "Agnoclast note:", like every other
26
+ // note since 0.9.299.
25
27
  //
26
28
  // ⚠ SELF-CONTAINED ON PURPOSE: setup copies this one file to ~/.cortex/hooks/ and Claude Code runs it with plain
27
29
  // `node` after every Write / Edit / Read, so it may import only Node built-ins (no npx start-up on the hot path).
@@ -33,7 +35,6 @@ import { createHash } from 'node:crypto'
33
35
 
34
36
  export const MAX_BYTES = 50 * 1024 * 1024
35
37
  export const RENUDGE_MS = 10 * 60 * 1000
36
- const UPLOAD_SETTING = 'documents.agent_uploads'
37
38
 
38
39
  const DOCUMENTS = new Set(['docx', 'doc', 'dotx', 'xlsx', 'xlsm', 'xls', 'pptx', 'ppt', 'potx', 'pdf', 'odt', 'ods', 'odp', 'rtf', 'pages', 'numbers', 'key'])
39
40
  const DELIVERABLES = new Set(['md', 'markdown', 'html', 'htm', 'csv', 'tsv', 'txt', 'ipynb', 'png', 'jpg', 'jpeg', 'gif', 'webp', 'svg'])
@@ -112,16 +113,15 @@ export function agnoclastCredentials({ home, env = process.env, read = readFileS
112
113
  return { token, base: (base || 'https://agnoclast.com').replace(/\/+$/, '') }
113
114
  }
114
115
 
115
- /** true / false from the server, or null when it could not be asked. */
116
+ /** true / false from the server's capture-status, or null when it could not be asked. */
116
117
  async function uploadsAllowed({ home, fetchImpl = globalThis.fetch }) {
117
118
  const { token, base } = agnoclastCredentials({ home })
118
119
  if (!token || !fetchImpl) return null
119
120
  try {
120
- const res = await fetchImpl(`${base}/api/settings`, { headers: { Authorization: `Bearer ${token}` }, signal: AbortSignal.timeout(4000) })
121
+ const res = await fetchImpl(`${base}/api/stored-files/capture-status`, { headers: { Authorization: `Bearer ${token}` }, signal: AbortSignal.timeout(4000) })
121
122
  if (!res.ok) return null
122
123
  const view = await res.json()
123
- const s = (view?.settings ?? []).find((x) => x?.key === UPLOAD_SETTING)
124
- return s ? Boolean(s.value) : null
124
+ return typeof view?.store === 'boolean' ? view.store : null
125
125
  } catch { return null }
126
126
  }
127
127
 
@@ -159,8 +159,8 @@ export async function runFileCapture({ input, home = homedir(), now = Date.now()
159
159
  state.uploads = await uploadsAllowed({ home, fetchImpl })
160
160
  state.uploadsAt = now
161
161
  }
162
- // Off: say nothing, the upload would only be refused. Unknown (offline, old server): say it, and let the tool report.
163
- if (state.uploads === false) { save(file, state); return null }
162
+ // Only a yes is a yes: not paid, uploads off, offline or an old server all say nothing.
163
+ if (state.uploads !== true) { save(file, state); return null }
164
164
  state.nudged = { ...state.nudged, [d.path]: now }
165
165
  save(file, state)
166
166
  return { hookSpecificOutput: { hookEventName: 'PostToolUse', additionalContext: nudgeText(d) } }
@@ -22,7 +22,7 @@ export const REGULAR_ONLY_TOOLS = [
22
22
  'list_records', 'read_record', 'timeline_pull', 'record_status', 'set_record_notes', 'set_record_privacy',
23
23
  'relabel_record_people', 'supersede_record', 'move_record', 'contain_record', 'pending_records', 'claim_record',
24
24
  'route_record', 'unroute_record', 'request_file', 'get_file', 'create_custom_source', 'search_spam_email',
25
- 'gmail_modify', 'draft_email_reply', 'request_send_email', 'send_imessage', 'add_to_brain',
25
+ 'gmail_modify', 'draft_email_reply', 'request_send_email', 'send_imessage',
26
26
  ]
27
27
 
28
28
  /** What a locked tool answers when the check itself could not be made. Nothing was run. */
@@ -11,7 +11,7 @@
11
11
  // That is safe because hiding a tool is a courtesy, and every gated route checks its own flag on the server.
12
12
 
13
13
  /** Tools any release flag gates — hidden when the server cannot be asked. Mirror of allGatedTools(). */
14
- export const GATED_FALLBACK = ['arrivals', 'attach_document', 'document_diff', 'export_page', 'file_arrival', 'file_document', 'find_documents', 'finish_task', 'get_document', 'hand_task', 'handed_tasks', 'hold_task', 'import_document_as_page', 'intake_shadow', 'list_documents', 'my_messages', 'my_tasks', 'pin_document', 'read_conversation', 'read_document', 'send_message', 'set_manager', 'tasks_waiting', 'upload_document_version']
14
+ export const GATED_FALLBACK = ['arrivals', 'attach_document', 'document_diff', 'export_page', 'file_arrival', 'file_document', 'find_documents', 'finish_task', 'get_document', 'hand_task', 'handed_tasks', 'hold_task', 'import_document_as_page', 'intake_shadow', 'list_documents', 'my_messages', 'my_tasks', 'pin_document', 'read_conversation', 'read_document', 'send_message', 'set_manager', 'store_file', 'tasks_waiting', 'upload_document_version']
15
15
 
16
16
  export const RELEASE_FETCH_TIMEOUT_MS = 2500
17
17
  /** A remembered answer older than this is not trusted: a week covers a quiet weekend without hiding tools for long. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theronap/agnoclast-mcp",
3
- "version": "0.9.301",
3
+ "version": "0.9.303",
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": {