gui: write name= to session/new, then agent params to session/{name}/agent/new

This commit is contained in:
Levi Neely 2026-08-01 18:41:16 +02:00
parent 68a84a2404
commit 153b40cbc7
1 changed files with 53 additions and 22 deletions

View File

@ -268,31 +268,62 @@ bool Ollie9pClient::createSession(const QString &cwd, const QString &name, const
{ {
if (cwd.isEmpty()) return false; if (cwd.isEmpty()) return false;
QStringList args; // Step 1: Create the session (name only)
args << "cwd=" + cwd; QString sessName = name;
if (!name.isEmpty()) args << "name=" + name; {
if (!backend.isEmpty()) args << "backend=" + backend; QProcess proc;
if (!model.isEmpty()) args << "model=" + model; QStringList args = {"-a", serverAddr(), "write", "session/new"};
if (!agent.isEmpty()) args << "agent=" + agent; proc.start(ninepBin(), args);
if (!remote.isEmpty()) args << "remote=" + remote; proc.waitForStarted(3000);
if (!agentAlias.isEmpty()) args << "agent_alias=" + agentAlias; QString input = "name=" + sessName;
proc.write(input.toUtf8());
proc.closeWriteChannel();
proc.waitForFinished(5000);
if (proc.exitCode() != 0) {
QString err = QString::fromUtf8(proc.readAllStandardError()).trimmed();
if (err.isEmpty())
err = QString::fromUtf8(proc.readAllStandardOutput()).trimmed();
qDebug() << "createSession (step 1) failed:" << err;
return false;
}
// Read the returned session name (may be auto-generated)
QByteArray out = proc.readAllStandardOutput().trimmed();
if (!out.isEmpty())
sessName = QString::fromUtf8(out);
}
QProcess proc; // Step 2: Create the agent within the session
QStringList fullArgs = {"-a", serverAddr(), "write", "session/new"}; {
proc.start(ninepBin(), fullArgs); QStringList agentArgs;
proc.waitForStarted(3000); agentArgs << "cwd=" + cwd;
if (!backend.isEmpty()) agentArgs << "backend=" + backend;
if (!model.isEmpty()) agentArgs << "model=" + model;
if (!agent.isEmpty()) agentArgs << "agent=" + agent;
if (!remote.isEmpty()) agentArgs << "remote=" + remote;
if (!agentAlias.isEmpty()) agentArgs << "agent_alias=" + agentAlias;
QString input = args.join(" "); QProcess proc;
proc.write(input.toUtf8()); QStringList args = {"-a", serverAddr(), "write", "session/" + sessName + "/agent/new"};
proc.closeWriteChannel(); proc.start(ninepBin(), args);
proc.waitForFinished(5000); proc.waitForStarted(3000);
proc.write(agentArgs.join(" ").toUtf8());
proc.closeWriteChannel();
proc.waitForFinished(5000);
if (proc.exitCode() != 0) { if (proc.exitCode() != 0) {
QString err = QString::fromUtf8(proc.readAllStandardError()).trimmed(); QString err = QString::fromUtf8(proc.readAllStandardError()).trimmed();
if (err.isEmpty()) if (err.isEmpty())
err = QString::fromUtf8(proc.readAllStandardOutput()).trimmed(); err = QString::fromUtf8(proc.readAllStandardOutput()).trimmed();
qDebug() << "createSession failed:" << err; qDebug() << "createSession (step 2) failed:" << err;
return false; // Clean up the session
QProcess killProc;
killProc.start(ninepBin(), {"-a", serverAddr(), "write", "session/" + sessName + "/ctl"});
killProc.waitForStarted(3000);
killProc.write("kill");
killProc.closeWriteChannel();
killProc.waitForFinished(3000);
return false;
}
} }
return true; return true;