docs/agent-api/ez-agent-csv.html

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>EzAgent CSV wire encoding</title>
  <style>
    :root { color-scheme: light dark; font-family: system-ui, sans-serif; line-height: 1.5; }
    body { max-width: 52rem; margin: 2rem auto; padding: 0 1rem; }
    code, pre { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
    pre { overflow-x: auto; padding: 1rem; background: #8882; border-radius: .3rem; }
    table { border-collapse: collapse; width: 100%; }
    th, td { border: 1px solid #8888; padding: .45rem; text-align: left; vertical-align: top; }
    .exits { padding: .75rem 1rem; border-left: .3rem solid #588; background: #8882; }
    .exits ul { margin: .4rem 0 0; padding-left: 1.25rem; }
  </style>
</head>
<body>
  <header>
    <h1>EzAgent CSV wire encoding</h1>
    <p>This compact, single-row field encoding is used only by contracts that explicitly select it. It defines encoding, not payload fields or macro extensions. The prepared Ruby Workflow uses it for identifiers and for its lossy projection through the existing 0.1 visualizer contract.</p>
    <aside class="exits">
      <strong>Looking for something else?</strong>
      <ul>
        <li>JSONL frames, transport, or lifecycle: <a href="jsonl-api.html">JSONL API</a>.</li>
        <li>The <code>ruby.workflow//0.1</code> request and reply schema: <a href="ruby-workflow-0.1.html">Ruby Workflow 0.1</a>.</li>
        <li>All API contracts: <a href="index.html">API index</a>.</li>
        <li>Go protocol ownership: <a href="../pkg/protocol.md">pkg/protocol</a>.</li>
      </ul>
    </aside>
  </header>

  <main>
    <section id="format">
      <h2>What exact row do I emit?</h2>
      <p>This is <strong>not RFC 4180</strong>: comma separates fields and apostrophe is the only quoting byte. The generic codec does not validate UTF-8 or reject CR/LF; payload contracts may impose those rules.</p>
      <pre>row       ::= empty-row | field (&quot;,&quot; field)*
field     ::= bare | quoted
bare      ::= zero or more bytes other than &quot;,&quot; or &quot;'&quot;
quoted    ::= &quot;'&quot; (byte other than &quot;'&quot; | &quot;''&quot;)* &quot;'&quot;
empty-row ::= the empty string</pre>
      <ul>
        <li>Emit a <code>bare</code> field only when it has neither comma nor apostrophe.</li>
        <li>Otherwise emit <code>quoted</code>; encode each literal apostrophe inside it as <code>''</code>.</li>
        <li>Do not add whitespace around separators. Double quotes have no special meaning.</li>
        <li>Never use an empty row to distinguish <code>[]</code> from <code>[&quot;&quot;]</code>: the encoder emits the empty string for both, and the Ruby parser reads it as <code>[]</code>.</li>
      </ul>
    </section>

    <section id="example">
      <h2>How do commas and apostrophes encode?</h2>
      <table>
        <thead><tr><th>Fields</th><th>Encoded row</th></tr></thead>
        <tbody>
          <tr><td><code>[&quot;a,b&quot;, &quot;c&quot;]</code></td><td><code>'a,b',c</code></td></tr>
          <tr><td><code>[&quot;can't&quot;]</code></td><td><code>'can''t'</code></td></tr>
          <tr><td><code>[&quot;x&quot;, &quot;a'b&quot;, &quot;y&quot;]</code></td><td><code>x,'a''b',y</code></td></tr>
          <tr><td><code>[&quot;a,'b&quot;]</code></td><td><code>'a,''b'</code></td></tr>
          <tr><td><code>[&quot;a&quot;, &quot;&quot;]</code></td><td><code>a,</code></td></tr>
        </tbody>
      </table>
      <p>A trailing separator produces a final empty field.</p>
    </section>

    <section id="consumers">
      <h2>What must a consumer reject?</h2>
      <p>Reject malformed quoting rather than guessing. A quoted field must close, and after its closing apostrophe only a comma or end of row is valid. Consumer validation is context-specific: the workflow TUI also rejects invalid UTF-8, CR/LF, and apostrophes in unquoted fields, and the prepared Workflow identifier decoder rejects invalid UTF-8 and apostrophes in unquoted fields. Do not rely on every generic helper having identical rejection checks; emit only the canonical form above.</p>
    </section>

    <section id="schema">
      <h2>Where do field meanings live?</h2>
      <p>CSV carries an ordered row only. Field names, ordering, types, and forward compatibility belong to each owning contract: prepared Workflow identifiers are documented in the <a href="../ez-agent-ruby/lib/ez_agent/workflow.md">Ruby Workflow API</a>, while visualizer rows belong to <a href="ruby-workflow-0.1.html">Ruby Workflow visualizer 0.1</a>.</p>
    </section>

    <section id="detail">
      <h2>Where is implementation detail?</h2>
      <ul>
        <li>Prepared Workflow identifier producer/decoder: <code>ez-agent-ruby/lib/ez_agent/workflow/identifiers.rb</code>.</li>
        <li>Historical visualizer decoding: <code>pkg/tui/workflow_visualizer.go</code>.</li>
        <li>Go parity codec: <code>pkg/protocol/csv.go</code> (<code>EncodeCSVRow</code>, <code>ParseCSVRow</code>).</li>
        <li>Stable regressions: <code>ez-agent-ruby/test/workflow_test.rb</code>, <code>pkg/protocol/csv_test.go</code>, and <code>pkg/tui/workflow_visualizer_test.go</code>.</li>
      </ul>
      <p><a href="index.html">Back to the API index</a>.</p>
    </section>
  </main>
</body>
</html>