import * as NodeServices from '@effect/platform-node/NodeServices';
import * as Effect from 'effect/Effect';
import * as Logger from 'effect/Logger';
import { runSshCommand, baseSshArgs } from './src/command.ts';
const target = { alias: 'netbird-sim', hostname: '127.0.0.1', username: null, port: null };
console.log('\x1b[2J\x1b[HSSH pre-banner SSO delay — real T3 SSH command / real OpenSSH');
console.log(`Commit: ${process.env.PROOF_SHA}`);
console.log('Linux | local sshd | synthetic host | no authentication key');
console.log('Config: ConnectTimeout 120; ProxyCommand prints SSO URL, waits 13s, then nc 127.0.0.1 22');
console.log('App SSH args: ' + baseSshArgs(target, { batchMode: 'yes' }).join(' '));
console.log('Overall app command budget: 60000ms');
console.log('\nStarting connection...');
const started = Date.now();
const timer = setInterval(() => console.log(`  Waiting for SSH banner... ${((Date.now()-started)/1000).toFixed(1)}s`), 1000);
const result = await Effect.runPromise(runSshCommand(target, {
  preHostArgs: ['-F', process.env.SSH_PROOF_CONFIG!],
  remoteCommandArgs: ['printf', 'connected'],
  timeoutMs: 60000,
}).pipe(Effect.match({onFailure: e => ({ok:false, stderr:e.stderr, message:e.message}), onSuccess: r => ({ok:true, ...r})}), Effect.provide(NodeServices.layer), Effect.provide(Logger.layer([]))));
clearInterval(timer);
console.log(`\nCompleted in ${Date.now()-started}ms`);
console.log(result.ok ? 'SSH COMMAND SUCCEEDED' : 'SSH COMMAND ERROR');
console.log(result.stderr);
console.log(result.stderr.includes('Connection timed out during banner exchange') ? 'OBSERVED: banner timeout before 13-second SSO step completes.' : result.stderr.includes('Permission denied') ? 'OBSERVED: passed the 13-second SSO delay and reached sshd authentication.' : 'OBSERVED: see output above.');
console.log('\nEnd of capture.');
