import assert from 'node:assert/strict' import fs from 'node:fs' import crypto from 'node:crypto' import { pathToFileURL } from 'node:url' const directory = 'src/renderer/src/workbuddy/conversation/recovered-fold-summary' const manifest = JSON.parse(fs.readFileSync(`${directory}/manifest.json`, 'utf8')) const sourceText = fs.readFileSync(`${directory}/index.mjs`, 'utf8') assert.equal(manifest.evidenceId, 'ev_717fa5e846e64d67ac19c8925d121bff632c0d3aefb3603b10858559cabb2dcb') assert.equal(manifest.sha256, '6c6ce63c93854783270e855572797d75e536e3b8d4548410e31fe9d147e1feb4') assert.equal(manifest.sourceOffsetsUtf16.descriptorCount, 40) assert.equal(manifest.extractedFunctions.length, 27) assert.equal(crypto.createHash('sha256').update(sourceText).digest('hex'), manifest.generatedSha256) const summary = await import(`${pathToFileURL(`${directory}/index.mjs`).href}?run=${Date.now()}`) const t = (key, params) => { if (key === 'metaFold.summary.compose') return `${params.verb}: ${params.object}` if (key === 'metaFold.summary.running') return `running(${params.text})` if (params?.topic !== undefined) return `${key}:${params.topic}` if (params?.count !== undefined) return `${key}:${params.count}` return key } const summarize = (parts, options = {}) => summary.computeSourceFoldSummary(parts, { ...options, t }) const oneRead = summarize([{ type: 'tool-call', tool: { name: 'Read', status: 'executed', args: { file_path: 'C:/work/src/readme.md' } } }]) assert.deepEqual(oneRead, { text: 'metaFold.summary.action.read: readme.md', status: 'success', isFallback: false }) const commandDoesNotUseCommandObject = summarize([{ type: 'tool-call', tool: { name: 'Bash', status: 'executed', args: { command: 'npm test' } } }]) assert.equal(commandDoesNotUseCommandObject.text, 'metaFold.summary.noObject.command') const readGroup = summarize([ { type: 'tool-call', tool: { name: 'Read', status: 'executed', args: { file_path: 'src/index.ts' } } }, { type: 'tool-call', tool: { name: 'list_dir', status: 'executed', args: { root: 'src' } } } ], { adjacentText: 'I will inspect the project.', isRunning: false }) assert.equal(readGroup.text, 'metaFold.summary.group.read:index.ts') assert.equal(readGroup.status, 'success') const waiting = summarize([ { type: 'tool-call', tool: { name: 'ExitPlanMode', status: 'pending' } }, { type: 'tool-call', tool: { name: 'Read', status: 'executed' } } ]) assert.equal(waiting.text, 'metaFold.summary.waitingPlan') assert.equal(waiting.status, 'waiting') const running = summarize([{ type: 'tool-call', tool: { name: 'WebSearch', status: 'stream_executing', args: { query: 'source fold summary' } } }], { isRunning: true }) assert.equal(running.status, 'running') assert.equal(running.text, 'running(metaFold.summary.action.webSearch: source fold summary)') const fallback = summarize([{ type: 'tool-call', tool: { name: 'unmapped_tool', status: 'executed' } }]) assert.deepEqual(fallback, { text: 'metaFold.summary.fallback', status: 'success', isFallback: true }) assert.throws(() => summary.computeSourceFoldSummary([], {}), /translator/) console.log('Recovered fold-summary closure regression passed (descriptor aliases, object selection, states, topics and labels).')