A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Handle single-quoted rel ids, sectPr order and hyperlink anchors
Fei24113df596cddf7e
diff --git a/ds-bot/office.js b/ds-bot/office.jsindex ab2df87b..70625bdf 100644--- a/ds-bot/office.js+++ b/ds-bot/office.js@@ -7842,7 +7842,7 @@ function addComment(pkg, getDoc, changed, { paragraph, text, anchor, author = "Bif (anchor) {const span = phraseRuns(doc, p, anchor);if (!span) throw new Error(`anchor "${anchor}" not found in ${paragraph}`);- p.insertBefore(rangeStart, span.firstRun);+ span.firstRun.parentNode.insertBefore(rangeStart, span.firstRun);span.lastRun.parentNode.insertBefore(rangeEnd, span.lastRun.nextSibling);span.lastRun.parentNode.insertBefore(ref, rangeEnd.nextSibling);} else {@@ -7944,7 +7944,8 @@ function resolveChanges(doc, accept) {}for (const c of [...parent.childNodes]) if (!keep.has(c.tagName) && c !== el) parent.removeChild(c);if (stored) {- const anchor = [...parent.childNodes].find((c) => keep.has(c.tagName)) ?? null;+ const kept = [...parent.childNodes].filter((c) => keep.has(c.tagName));+ const anchor = parent.tagName === "w:sectPr" ? kept.length > 0 ? kept.at(-1).nextSibling : parent.firstChild === el ? null : parent.firstChild : kept[0] ?? el;for (const s of [...stored.childNodes]) parent.insertBefore(s, anchor);}parent.removeChild(el);@@ -8281,7 +8282,7 @@ function pptxClean(pkg, { dryRun = false } = {}) {const xml = pkg.get(owner) ?? Buffer.alloc(0);for (const [id, rel] of [...map]) {if (rel.mode !== "Internal" || !CONTENT_REL.test(rel.type)) continue;- if (!xml.includes(`"${id}"`)) map.delete(id);+ if (!xml.includes(`"${id}"`) && !xml.includes(`'${id}'`)) map.delete(id);}}const listed = new Set(deckOrder(pkg).map((e) => e.part));diff --git a/ds-bot/src/office/docx.js b/ds-bot/src/office/docx.jsindex f999257e..d5e27eb5 100644--- a/ds-bot/src/office/docx.js+++ b/ds-bot/src/office/docx.js@@ -506,7 +506,8 @@ function addComment(pkg, getDoc, changed, { paragraph, text, anchor, author = 'Bif (anchor) {const span = phraseRuns(doc, p, anchor)if (!span) throw new Error(`anchor "${anchor}" not found in ${paragraph}`)- p.insertBefore(rangeStart, span.firstRun)+ // The phrase can sit inside a w:hyperlink — insert beside the run itself.+ span.firstRun.parentNode.insertBefore(rangeStart, span.firstRun)span.lastRun.parentNode.insertBefore(rangeEnd, span.lastRun.nextSibling)span.lastRun.parentNode.insertBefore(ref, rangeEnd.nextSibling)} else {@@ -594,7 +595,13 @@ export function resolveChanges(doc, accept) {if (parent.tagName === 'w:sectPr') { keep.add('w:headerReference'); keep.add('w:footerReference') }for (const c of [...parent.childNodes]) if (!keep.has(c.tagName) && c !== el) parent.removeChild(c)if (stored) {- const anchor = [...parent.childNodes].find(c => keep.has(c.tagName)) ?? null+ // pPr keeps its mark rPr/sectPr at the end; a sectPr's header/footer+ // references come first, so restored children go after them (the+ // change element is removed anyway).+ const kept = [...parent.childNodes].filter(c => keep.has(c.tagName))+ const anchor = parent.tagName === 'w:sectPr'+ ? (kept.length > 0 ? kept.at(-1).nextSibling : parent.firstChild === el ? null : parent.firstChild)+ : (kept[0] ?? el)for (const s of [...stored.childNodes]) parent.insertBefore(s, anchor)}parent.removeChild(el)diff --git a/ds-bot/src/office/pptx.js b/ds-bot/src/office/pptx.jsindex 828200cf..cbed3a59 100644--- a/ds-bot/src/office/pptx.js+++ b/ds-bot/src/office/pptx.js@@ -353,7 +353,8 @@ export function pptxClean(pkg, { dryRun = false } = {}) {const xml = pkg.get(owner) ?? Buffer.alloc(0)for (const [id, rel] of [...map]) {if (rel.mode !== 'Internal' || !CONTENT_REL.test(rel.type)) continue- if (!xml.includes(`"${id}"`)) map.delete(id)+ // Non-Office generators can write single-quoted attributes.+ if (!xml.includes(`"${id}"`) && !xml.includes(`'${id}'`)) map.delete(id)}}// Slides not in sldIdLst.diff --git a/ds-bot/test/office.test.js b/ds-bot/test/office.test.jsindex 46157b26..9cd98099 100644--- a/ds-bot/test/office.test.js+++ b/ds-bot/test/office.test.js@@ -10,8 +10,8 @@ import assert from 'node:assert'import { readZip } from '../src/office/zip.js'import { Package } from '../src/office/package.js'import { checkPackage, fixPackage } from '../src/office/check.js'-import { docxRead, docxEdit } from '../src/office/docx.js'-import { pptxInventory, pptxLayout } from '../src/office/pptx.js'+import { docxRead, docxEdit, resolveChanges } from '../src/office/docx.js'+import { pptxInventory, pptxLayout, pptxClean } from '../src/office/pptx.js'import { xlsxInventory, xlsxRead } from '../src/office/xlsx.js'import { decodePng, encodePng, contactSheet } from '../src/office/png.js'import { parseXml, elementsOf, childrenOf, textOf } from '../src/office/xml.js'@@ -424,6 +424,49 @@ describe('check rules (review 10, 11)', () => {})})+describe('re-review fixes', () => {+ test('clean keeps a single-quoted r:embed', () => {+ const pkg = Package.open(fixture('sample.pptx'))+ const rel = [...pkg.relsOf('ppt/slides/slide1.xml').values()].find(r => r.type.endsWith('/image'))+ const xml = String(pkg.get('ppt/slides/slide1.xml')).replace(`"${rel.id}"`, `'${rel.id}'`)+ pkg.put('ppt/slides/slide1.xml', xml)+ assert.ok(pptxClean(pkg, { dryRun: true }).removed.every(n => n !== 'ppt/media/image1.png'))+ })+ test('sectPr reject puts header/footer references before restored properties', () => {+ const pkg = Package.open(fixture('sample.docx'))+ const doc = pkg.xml('word/document.xml')+ const sectPr = elementsOf(doc.documentElement, 'w:sectPr')[0]+ const ref = doc.createElement('w:headerReference')+ ref.setAttribute('w:type', 'default')+ sectPr.insertBefore(ref, sectPr.firstChild)+ const change = doc.createElement('w:sectPrChange')+ const stored = doc.createElement('w:sectPr')+ const sz = doc.createElement('w:pgSz')+ sz.setAttribute('w:w', '11906'); sz.setAttribute('w:h', '16838')+ stored.appendChild(sz); change.appendChild(stored)+ sectPr.appendChild(change)+ resolveChanges(doc, false)+ const names = childrenOf(sectPr).map(c => c.tagName)+ assert.equal(names[0], 'w:headerReference')+ assert.ok(names.includes('w:pgSz'))+ assert.ok(!names.includes('w:sectPrChange'))+ })+ test('comment anchor inside a w:hyperlink wraps the phrase', () => {+ const pkg = Package.open(fixture('sample.docx'))+ const doc = pkg.xml('word/document.xml')+ const p = parseXml(`<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:hyperlink w:history="1" w:anchor="top"><w:r><w:t xml:space="preserve">click here text</w:t></w:r></w:hyperlink></w:p>`).documentElement+ childrenOf(doc.documentElement, 'w:body')[0].appendChild(doc.importNode(p, true))+ pkg.putXml('word/document.xml', doc)+ const dir = tmp(), out = join(dir, 'hl.docx')+ writeFileSync(join(dir, 'hl-src.docx'), pkg.save())+ cli('docx', 'edit', join(dir, 'hl-src.docx'), '-o', out, '--ops',+ JSON.stringify([{ comment: { paragraph: 'p7', text: 'hi', anchor: 'here' } }]))+ const read = docxRead(Package.open(out))+ assert.ok(read.comments.some(c => c.text === 'hi' && c.anchorsTo === 'p7'))+ assert.deepEqual(checkPackage(Package.open(out)), [])+ })+})+describe('JSON findings shape (review 14)', () => {test('findings come back ok:true with exit 1', () => {const dir = tmp()