// Browser-console driver for a fresh paired development server.
// Start each checkout with T3CODE_DEV_SEED=0 vp run dev.
// Set the viewport to 1280x800 and appearance to light on both sides.
// Native seed: use the app or `t3 thread start` with OpenCode and a configured
// model supplied privately; title "Archive proof parent"; prompt:
// "Launch exactly one native task-tool subagent named Reply OK using the general
// subagent type. Ask it to reply OK only. Wait for completion, then reply Done.
// Do not use T3 delegation tools, read files, or run commands."
// Wait for completion. The native child is real provider-created state.
// A subsequent resume request to create a grandchild failed on both sides with
// a provider-turn ordinal UNIQUE constraint; recursive proof uses the separate
// synthetic Replay tree below, created entirely through public server commands.
window.evidenceRpc = (tag, payload) => new Promise((resolve, reject) => {
  const socket = new WebSocket(location.origin.replace('http', 'ws') + '/ws?orchestrationProtocol=2');
  socket.onopen = () => socket.send(JSON.stringify({_tag:'Request',id:'1',tag,payload,headers:[]}));
  socket.onmessage = ({data}) => {
    const response = JSON.parse(data);
    if(response._tag === 'Exit') {
      socket.close();
      response.exit._tag === 'Success' ? resolve(response.exit.value) : reject(response.exit);
    }
  };
  socket.onerror = () => reject(new Error('WebSocket failed'));
});
window.proofCommand = (command) => evidenceRpc('orchestration.dispatchCommand', {commandId:crypto.randomUUID(), ...command});
window.proofProjection = threadId => evidenceRpc('orchestration.getThreadProjection',{threadId});
window.seedRecursiveRoot = async (projectId, modelSelection) => {
  const threadId = 'proof-tree-' + crypto.randomUUID();
  await proofCommand({type:'thread.create',threadId,projectId,title:'Recursive archive proof',modelSelection,runtimeMode:'full-access',interactionMode:'default',branch:null,worktreePath:null,createdBy:'user',creationSource:'web'});
  await proofCommand({type:'message.dispatch',threadId,messageId:crypto.randomUUID(),text:'Synthetic archive proof',attachments:[],dispatchMode:{type:'start_immediately'},createdBy:'user',creationSource:'web'});
  return threadId;
};
window.seedDescendant = async (parentThreadId,title,modelSelection) => {
  const parent = await proofProjection(parentThreadId);
  const run = parent.runs.at(-1);
  await proofCommand({type:'delegated_task.request',parentThreadId,parentRunId:run.id,parentNodeId:run.rootNodeId,task:'Synthetic descendant for archive proof',title,modelSelection,runtimeMode:'full-access',interactionMode:'default',createdBy:'agent',creationSource:'mcp'});
  return (await proofProjection(parentThreadId)).subagents.at(-1).childThreadId;
};
// Supply the Replay provider selection for its question scenario privately.
// root = await seedRecursiveRoot(projectId,replaySelection);
// child = await seedDescendant(root,'Child archive proof',replaySelection);
// grandchild = await seedDescendant(child,'Grandchild archive proof',replaySelection);
// await proofCommand({type:'thread.stop',threadId:root});
// Wait for all runs to become terminal. No database writes or mocked projections.
window.proofStates = async ids => Promise.all(ids.map(async id => {
  const {thread} = await proofProjection(id);
  return {id:thread.id,title:thread.title,archivedAt:thread.archivedAt,lineage:thread.lineage};
}));
// Privacy mask: hide only composer/provider and workspace/machine chrome.
// Thread rows, archive controls, and archive contents remain untouched.
const privacy = document.createElement('style');
privacy.textContent = '[aria-label="Message input"], [aria-label="Thread details"] {visibility:hidden !important}';
document.head.append(privacy);
// Recorded interaction, identically on both sides:
// 1. Right-click Archive proof parent -> Archive thread.
// 2. Settings -> Archive. Capture active listing with listing.mjs.
// 3. Click Unarchive Archive proof parent. Capture listing.
// 4. Close Settings. Right-click Recursive archive proof -> Archive thread.
// 5. Settings -> Archive. Capture all three archivedAt states and active listing.
// 6. Click Unarchive Recursive archive proof. Capture states and active listing.
// 7. Independently archive child through proofCommand; unarchive grandchild.
// 8. Close Settings. Right-click Recursive archive proof -> Archive thread.
// 9. Settings -> Archive. Capture states and active listing.
// 10. Click Unarchive Recursive archive proof. Capture states and active listing.
// Expected head: parent/child/grandchild archive together and restore together;
// in the independent-child case only root and grandchild restore.
