@theronap/agnoclast-mcp 0.9.299 → 0.9.300
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.mjs +5 -2
- package/lib/closeout_wiki.mjs +17 -4
- package/package.json +1 -1
package/lib/closeout.mjs
CHANGED
|
@@ -543,8 +543,11 @@ async function closeSession(session, { env, home, stopAtLog = false, write = tru
|
|
|
543
543
|
if (!write) return { ok: true, cost, digest, wiki }
|
|
544
544
|
const accepted = wiki?.accepted ?? []
|
|
545
545
|
// Pages first, so the record that follows has them attached: the server attaches what this session wrote.
|
|
546
|
-
|
|
547
|
-
const
|
|
546
|
+
// An edit that could not land goes on the record under "Pages to update", so it is not lost.
|
|
547
|
+
const applied = WIKI_WRITES && accepted.length ? await applyWikiEdits(tools, accepted, currentPage(tools)) : []
|
|
548
|
+
const unlanded = WIKI_WRITES ? applied.filter((r) => !r.ok).map((r) => r.edit) : accepted
|
|
549
|
+
const written = await writeSegments(tools, session.id, withPageProposals(digest.segments, unlanded))
|
|
550
|
+
const edits = applied.map(({ edit, ...r }) => r)
|
|
548
551
|
return { ok: written.ok, records: written.records, why: written.ok ? null : written.text.slice(0, 600), cost, digest, wiki, edits }
|
|
549
552
|
} finally {
|
|
550
553
|
await tools.close().catch(() => {})
|
package/lib/closeout_wiki.mjs
CHANGED
|
@@ -164,12 +164,25 @@ export function withPageProposals(segments, accepted) {
|
|
|
164
164
|
})
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
/**
|
|
168
|
-
|
|
167
|
+
/**
|
|
168
|
+
* Land the accepted edits. `edit_page` is the only write here. A page another session changed in the meantime is
|
|
169
|
+
* refused by its version (2026-11-03: two sessions rewrote one page while a run read it), so the page is read again
|
|
170
|
+
* and the edit retried once, only while its passage is still there exactly once. Each result keeps its edit, so a
|
|
171
|
+
* caller can put what failed on the record instead.
|
|
172
|
+
*/
|
|
173
|
+
export async function applyWikiEdits(tools, accepted, readPage) {
|
|
169
174
|
const results = []
|
|
175
|
+
const edit = async (e, version) => {
|
|
176
|
+
const r = await tools.call('edit_page', { name: e.page, heading: e.heading, old_string: e.old_string, new_string: e.new_string, base_version: version, reason: e.reason })
|
|
177
|
+
return { ok: !r.isError && r.text.startsWith('Edited'), text: r.text.slice(0, 200) }
|
|
178
|
+
}
|
|
170
179
|
for (const e of accepted) {
|
|
171
|
-
|
|
172
|
-
|
|
180
|
+
let r = await edit(e, e.version)
|
|
181
|
+
if (!r.ok && readPage && /version/i.test(r.text)) {
|
|
182
|
+
const page = await readPage(e.page, [e.brain])
|
|
183
|
+
if (page && page.text.split(e.old_string).length === 2) r = await edit(e, page.version)
|
|
184
|
+
}
|
|
185
|
+
results.push({ page: e.page, ...r, edit: e })
|
|
173
186
|
}
|
|
174
187
|
return results
|
|
175
188
|
}
|
package/package.json
CHANGED