Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

YamlReporter: structuredOutput is stored as a JSON-encoded string inside a block scalar, not as native YAML data

Aperta Adatta ai principianti
#76 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
typescript, yaml
Ambito
tooling

Direzione di ricerca

Inizia da src/reporters/yaml.ts ed esamina il test esistente del reporter YAML, che attualmente verifica solo sottostringhe serializzate. Esegui quel test prima di modificare il percorso structuredOutput. Il lavoro è completato quando un parser YAML restituisce structuredOutput come oggetto con gli stessi dati annidati dell’input, mentre il comportamento esistente del report rimane invariato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug S3

Observed behavior

When a successful result includes structuredOutput, YamlReporter.append serialises it by JSON.stringify'ing the value and writing the resulting text into a YAML block scalar:

// src/reporters/yaml.ts
if (result.structuredOutput !== undefined) {
  lines.push('structuredOutput: |');
  const json = JSON.stringify(result.structuredOutput, null, 2);
  for (const line of formatBlockScalar(json).split('\n')) {
    lines.push(line === '' ? /* istanbul ignore next */ '' : `  ${line}`);
  }
}

A consumer parsing the report file with any YAML loader gets back structuredOutput as a string containing JSON, not as the structured object the agent produced. To use the data they have to do a second JSON.parse step that they would not have to do for any other field in the report.

This is inconsistent with JsonlReporter, which spreads the result into the output line:

// src/reporters/jsonl.ts
const output = `${JSON.stringify({ ...prompt, ...result })}\n`;

For the JSONL reporter, structuredOutput round-trips as a nested object, so a consumer can read entry.structuredOutput.found directly. Switching the configured reporter from JSONL to YAML (or to the default, which is YAML) silently changes the shape of structuredOutput from "structured object" to "JSON-encoded string".

The existing test only asserts that the YAML contains the substrings "found": true and "a.ts": "bug", so the bug is not caught.

Expected behavior

structuredOutput is documented in src/types.ts as "the parsed object that conforms to the schema". A reporter that persists a result entry should preserve that shape: parsing the YAML report should yield an object, not a string. This is also what users will expect from a structured-data report format.

Minimal reproduction

import { mkdtemp, readFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { parseAllDocuments } from 'yaml';

import { YamlReporter } from 'loop-the-loop/reporters/yaml';

const dir = await mkdtemp(join(tmpdir(), 'yaml-structured-bug-'));
const reporter = await YamlReporter.create({ outputDir: dir, jobName: 'demo' });

await reporter.append(
  { id: 'a', prompt: 'p' },
  {
    status: 'success',
    output: 'ok',
    structuredOutput: { found: true, items: ['a', 'b'] },
  },
);

const text = await readFile(join(dir, 'demo-report.yaml'), 'utf-8');
const obj = parseAllDocuments(text)[0].toJS();

console.log(typeof obj.structuredOutput);    // 'string'
console.log(obj.structuredOutput.found);     // undefined
console.log(JSON.parse(obj.structuredOutput).found); // true

Suggested fix

Emit structuredOutput as native YAML so it round-trips as an object. The minimal change is to use a YAML serializer for this single field (the rest of the entry could stay hand-written for now):

import { stringify } from 'yaml';

if (result.structuredOutput !== undefined) {
  // `stringify` returns a trailing newline; indent under the parent key
  const yaml = stringify(result.structuredOutput, { indent: 2 });
  lines.push('structuredOutput:');
  for (const line of yaml.trimEnd().split('\n')) {
    lines.push(`  ${line}`);
  }
}

The longer-term fix is to delegate serialization of the whole entry to a YAML library, which also resolves the related issues #69 (id field not escaped) and #75 (block scalar indent bug). A test that round-trips structuredOutput through a real YAML parser and asserts deep-equality with the input would prevent regression.

Lingua principale
TypeScript
Stelle
2
Fork
1
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di joewalker/loop-the-loop

Tutte le issue di joewalker/loop-the-loop

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.