A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Read the AGENTS.md review's edit when it slips on the format
Fei24118c635eb65e19
diff --git a/ds-bot/dev/learning-eval.mjs b/ds-bot/dev/learning-eval.mjsindex 89ed5d90..7d5dd2e1 100644--- a/ds-bot/dev/learning-eval.mjs+++ b/ds-bot/dev/learning-eval.mjs@@ -9,7 +9,7 @@// node --import ./test/harness-resolve.mjs dev/learning-eval.mjs [--kind skill|agents] [--reps 3] [--cases case-file.json] [--only id,id] [--out report.json]import { readFileSync, writeFileSync } from 'node:fs'import { parseArgs } from 'node:util'-import { agentsProblem, agentsRequest, agentsSystem, applyEdits, parseJson, skillProblem, skillRequest, skillSystem, LEARNING } from '../src/host/learning.js'+import { agentsAnswer, agentsProblem, agentsRequest, agentsSystem, applyEdits, parseJson, skillProblem, skillRequest, skillSystem, LEARNING } from '../src/host/learning.js'import { writtenIn } from '../src/host/memory.js'const { values: args } = parseArgs({ options: { kind: { type: 'string', default: 'skill' }, reps: { type: 'string', default: '3' }, only: { type: 'string' }, cases: { type: 'string' }, out: { type: 'string' }, stage: { type: 'string', default: 'decide,effect' } } })@@ -57,7 +57,7 @@ if (args.kind === 'agents') {const request = agentsRequest({ folder: '/project', current, lines: entry.lines, declined: [], language: writtenIn(user, 'English') })const reply = await chat(agentsSystem(), request)tokens += reply.tokens- const proposal = parseJson(reply.text)+ const proposal = agentsAnswer(reply.text, current)const problem = agentsProblem(proposal, current)const misses = []if (entry.expect === 'none') {diff --git a/ds-bot/src/host/learning.js b/ds-bot/src/host/learning.jsindex 28dc0c66..710a40ff 100644--- a/ds-bot/src/host/learning.js+++ b/ds-bot/src/host/learning.js@@ -202,6 +202,33 @@ export function applyEdits(current, edits) {return text}+// The review's answer as a proposal. A single edit written as the answer itself, with+// its operation as the action, is that edit; a replacement with no text removes; lines+// one edit names that stand apart in the file, each once, are one edit each.+export function agentsAnswer(reply, current) {+ let answer = parseJson(reply)+ if (['add', 'replace', 'remove'].includes(answer?.action)) {+ const { action, ...edit } = answer+ answer = { action: 'edit', edits: [{ op: action, ...edit }] }+ }+ if (!Array.isArray(answer?.edits)) return answer+ const lines = lineBlock(current ?? '')+ const apart = edit => {+ if (edit?.op !== 'replace' && edit?.op !== 'remove') return [edit]+ const old = lineBlock(textOf(edit.old))+ const text = lineBlock(textOf(edit.text))+ if (old.length < 2 || occurrences(lines, old).length > 0 || old.some(line => occurrences(lines, [line]).length !== 1)) return [edit]+ if (edit.op === 'replace' && text.length !== old.length) return [edit]+ return old.map((line, index) => ({ ...edit, old: line, ...(edit.op === 'replace' ? { text: text[index] } : {}) }))+ }+ const removes = edit => {+ const { text, ...rest } = edit+ return { ...rest, op: 'remove' }+ }+ const edits = answer.edits.map(edit => edit?.op === 'replace' && textOf(edit.text).trim() === '' ? removes(edit) : edit)+ return { ...answer, edits: edits.flatMap(apart) }+}+export function agentsProblem(proposal, current) {if (proposal === undefined) return 'the answer is not a JSON object'if (proposal.action === 'none') return undefined@@ -421,7 +448,7 @@ export function install(rt) {const language = writtenIn(lines.filter(line => line.startsWith('User: ')).map(line => line.slice(6)), rt.uiLanguage?.())const request = agentsRequest({ folder, current, lines, declined: data().declined, language })const reply = await rt.botShot(bot, agentsSystem(), request, { sessionId: rt.chatOf(bot.id), kind: 'memory' })- const answer = parseJson(reply)+ const answer = agentsAnswer(reply, current)if (answer === undefined || answer === null || typeof answer !== 'object') throw new Error('the answer is not a JSON object')if (Array.isArray(answer.edits) && answer.edits.some(edit => [edit?.text, edit?.why].some(value => typeof value === 'string' && rt.redactSecrets(value) !== value))) {rt.warn('ds-bot: the AGENTS.md review of %s proposed content containing a saved secret', bot.name)diff --git a/ds-bot/test/learning.test.js b/ds-bot/test/learning.test.jsindex 10b868b0..9a28468b 100644--- a/ds-bot/test/learning.test.js+++ b/ds-bot/test/learning.test.js@@ -4,7 +4,7 @@ import { tmpdir } from 'node:os'import { join } from 'node:path'import { test } from 'node:test'import { createRuntime } from '../index.js'-import { agentsProblem, agentsRequest, applyEdits, LEARNING, parseJson, skillProblem, withoutReviewedAgentsRecords } from '../src/host/learning.js'+import { agentsAnswer, agentsProblem, agentsRequest, applyEdits, LEARNING, parseJson, skillProblem, withoutReviewedAgentsRecords } from '../src/host/learning.js'import { fakeContext } from './fake-ctx.js'const TEAM = {@@ -171,6 +171,25 @@ test('agentsProblem validates edit safety and whole-line matches', () => {assert.match(agentsProblem(large, long), /too large/)})+test('agentsAnswer reads an edit written as the answer, an empty replacement, and lines apart as edits', () => {+ const current = '# Project\n- Use yarn.\n- Do not edit vendor/.\n- Run `yarn test`.\n'+ const why = 'The user moved the project to pnpm.'+ const answer = value => agentsAnswer(JSON.stringify(value), current)+ const flat = answer({ action: 'replace', old: '- Use yarn.', text: '- Use pnpm.', why })+ assert.deepEqual(flat, { action: 'edit', edits: [{ op: 'replace', old: '- Use yarn.', text: '- Use pnpm.', why }] })+ assert.equal(agentsProblem(flat, current), undefined)+ assert.deepEqual(answer({ action: 'edit', edits: [{ op: 'replace', old: '- Use yarn.', text: ' ', why }] }).edits, [{ op: 'remove', old: '- Use yarn.', why }])+ const apart = answer({ action: 'edit', edits: [{ op: 'replace', old: '- Use yarn.\n- Run `yarn test`.', text: '- Use pnpm.\n- Run `pnpm test`.', why }] })+ assert.deepEqual(apart.edits.map(edit => [edit.old, edit.text]), [['- Use yarn.', '- Use pnpm.'], ['- Run `yarn test`.', '- Run `pnpm test`.']])+ assert.equal(applyEdits(current, apart.edits), '# Project\n- Use pnpm.\n- Do not edit vendor/.\n- Run `pnpm test`.\n')+ assert.equal(answer({ action: 'edit', edits: [{ op: 'remove', old: '- Use yarn.\n- Run `yarn test`.', why }] }).edits.length, 2)+ // Lines apart with a different number of new lines stay one edit, and the check refuses it.+ const uneven = answer({ action: 'edit', edits: [{ op: 'replace', old: '- Use yarn.\n- Run `yarn test`.', text: '- Use pnpm.', why }] })+ assert.match(agentsProblem(uneven, current), /exactly once/)+ assert.deepEqual(answer({ action: 'none', reason: 'Routine work.' }), { action: 'none', reason: 'Routine work.' })+ assert.equal(agentsAnswer('no JSON here', current), undefined)+})+test('applyEdits supports end and anchored add, replace, remove, and a new file', () => {const current = '# Project\n- Existing rule\n'assert.equal(applyEdits(current, [{ op: 'add', after: '', text: '- End rule' }]), '# Project\n- Existing rule\n- End rule\n')