Skip to content

Persistent Context Across Sessions for Every Agent – Captures everything your agent does during sessions, compresses it with AI, and injects relevant context back into future sessions. Works with Claude Code, OpenClaw, Codex, Gemini, Hermes, Copilot, OpenCode + More

4.2 KB
Raw Blame
import { describe, expect, it } from 'bun:test';
import { extractTranscriptFileActivityFromJsonl } from '../../src/shared/deliverables-transcript.js';

// Native rollout shapes from the transcript-watch Codex fixture and the prompt importer's response-item reader.
const timestamp = '2026-11-04T11:00:00Z';
const row = (type: string, payload: Record<string, unknown>) => JSON.stringify({ timestamp, type, payload });
const user = (text: string) => row('response_item', { type: 'message', role: 'user', content: [{ type: 'input_text', text }] });
const answer = (text: string, phase = 'final_answer') => row('response_item', { type: 'message', role: 'assistant', phase, content: [{ type: 'output_text', text }] });
const turn = (id: string) => row('event_msg', { type: 'task_started', turn_id: id });
const result = (call_id: string, output: string) => row('response_item', { type: 'custom_tool_call_output', call_id, output });
const call = (id: string, name = 'apply_patch') => row('response_item', { type: 'custom_tool_call', call_id: id, name,
  input: '*** Begin Patch\n*** Add File: unconfirmed.png\n+data\n*** End Patch' });
const scan = (rows: string[], turnId = 'my-turn') => extractTranscriptFileActivityFromJsonl(rows.join('\n'), { codexTurnId: turnId });

describe('Codex native Stop deliverables', () => {
  it('keeps only acknowledged patch outputs and explicitly linked final files in the matching turn', () => {
    const batch = [
      turn('old-turn'), user('Older work'), answer('[Old](/tmp/old.pdf)'),
      turn('my-turn'), user('Make my board'), call('patch'),
      result('patch', JSON.stringify({ output:'Success. Updated the following files:\nA board.png\nM map.pdf\nD old.png', metadata:{exit_code:0} })),
      call('incomplete'), call('failed'), result('failed','Failed to apply patch'), result('other','Success. Updated the following files:\nM other.pdf'),
      call('shell','exec_command'), result('shell','Success. Updated the following files:\nA shell.pdf'),
      answer('[Draft](/tmp/in-progress.png)','commentary'),
      answer('[Final](sandbox:/tmp/final%20board.pdf) [Site](https://example.com/) <private>[omit](/tmp/personal.png)</private>'),
    ];
    const data = scan(batch);
    expect(data.promptSeen).toBe(true);
    expect(data.privateTurn).toBe(false);
    expect(data.writes.map(w => [w.path, w.toolUseId])).toEqual([
      ['board.png','patch'], ['map.pdf','patch'], ['/tmp/final board.pdf',null],
    ]);
    expect(scan(batch,'a-different-turn').writes).toEqual([]);
  });
  it('uses the paired Stop final answer when the native message has not been flushed yet', () => {
    const options = { codexTurnId:'my-turn', codexFinalAnswer:{text:'[Deck](/tmp/new.pdf)', at:99} };
    const current = [turn('my-turn'),user('Make a deck')].join('\n');
    expect(extractTranscriptFileActivityFromJsonl(current,options).writes).toMatchObject([{path:'/tmp/new.pdf', occurredAtEpoch:99, toolUseId:null}]);
    expect(extractTranscriptFileActivityFromJsonl(current,{...options,codexTurnId:'other'}).writes).toEqual([]);
    expect(extractTranscriptFileActivityFromJsonl([turn('my-turn'),user('<private>secret</private>')].join('\n'),options).writes).toEqual([]);
  });
  it('keeps injected instructions from changing the privacy scope, ignores imported turns and retains no inherited fork artifacts', () => {
    const secret = [turn('my-turn'), user('<private>Make letters</private>'), user('<environment_context>context</environment_context>'), answer('[Letters](/tmp/letters.pdf)')];
    expect(scan(secret)).toMatchObject({ promptSeen:true, privateTurn:true, writes:[] });
    const imported = 'external-import-turn-001';
    expect(scan([turn(imported),user('Old work'),answer('[Old](/tmp/old.pdf)')],imported).writes).toEqual([]);
    const fork = [row('session_meta',{id:'child',forked_from_id:'parent'}),turn('my-turn'),user('Parent'),answer('[Old](/tmp/old.png)'),
      row('event_msg',{type:'thread_settings_applied',thread_id:'child'}),turn('child-turn'),user('Make mine'),
      row('event_msg',{type:'task_complete',turn_id:'child-turn',last_agent_message:'[Child report](</tmp/child report.pdf>)'})];
    expect(scan(fork,'child-turn').writes.map(w => w.path)).toEqual(['/tmp/child report.pdf']);
  });
});