@theronap/agnoclast-mcp 0.9.302 → 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.
- package/lib/closeout_wiki.mjs +45 -6
- package/package.json +1 -1
package/lib/closeout_wiki.mjs
CHANGED
|
@@ -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 =
|
|
10
|
-
const
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
/**
|
package/package.json
CHANGED