feat(cli): add sessions list/resume/destroy subcommands (#146)
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
Co-authored-by: Jason Woltje <jason@diversecanvas.com> Co-committed-by: Jason Woltje <jason@diversecanvas.com>
This commit was merged in pull request #146.
This commit is contained in:
@@ -106,6 +106,117 @@ program
|
||||
},
|
||||
);
|
||||
|
||||
// ─── sessions ───────────────────────────────────────────────────────────
|
||||
|
||||
const sessionsCmd = program.command('sessions').description('Manage active agent sessions');
|
||||
|
||||
sessionsCmd
|
||||
.command('list')
|
||||
.description('List active agent sessions')
|
||||
.option('-g, --gateway <url>', 'Gateway URL', 'http://localhost:4000')
|
||||
.action(async (opts: { gateway: string }) => {
|
||||
const { loadSession, validateSession } = await import('./auth.js');
|
||||
const { fetchSessions } = await import('./tui/gateway-api.js');
|
||||
|
||||
const session = loadSession(opts.gateway);
|
||||
if (!session) {
|
||||
console.error('Not signed in. Run `mosaic login` first.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const valid = await validateSession(opts.gateway, session.cookie);
|
||||
if (!valid) {
|
||||
console.error('Session expired. Run `mosaic login` again.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await fetchSessions(opts.gateway, session.cookie);
|
||||
if (result.total === 0) {
|
||||
console.log('No active sessions.');
|
||||
return;
|
||||
}
|
||||
console.log(`Active sessions (${result.total}):\n`);
|
||||
for (const s of result.sessions) {
|
||||
const created = new Date(s.createdAt).toLocaleString();
|
||||
const durationSec = Math.round(s.durationMs / 1000);
|
||||
console.log(` ID: ${s.id}`);
|
||||
console.log(` Model: ${s.provider}/${s.modelId}`);
|
||||
console.log(` Created: ${created}`);
|
||||
console.log(` Prompts: ${s.promptCount}`);
|
||||
console.log(` Duration: ${durationSec}s`);
|
||||
if (s.channels.length > 0) {
|
||||
console.log(` Channels: ${s.channels.join(', ')}`);
|
||||
}
|
||||
console.log('');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err instanceof Error ? err.message : String(err));
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
sessionsCmd
|
||||
.command('resume <id>')
|
||||
.description('Resume an existing agent session in the TUI')
|
||||
.option('-g, --gateway <url>', 'Gateway URL', 'http://localhost:4000')
|
||||
.action(async (id: string, opts: { gateway: string }) => {
|
||||
const { loadSession, validateSession } = await import('./auth.js');
|
||||
|
||||
const session = loadSession(opts.gateway);
|
||||
if (!session) {
|
||||
console.error('Not signed in. Run `mosaic login` first.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const valid = await validateSession(opts.gateway, session.cookie);
|
||||
if (!valid) {
|
||||
console.error('Session expired. Run `mosaic login` again.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const { render } = await import('ink');
|
||||
const React = await import('react');
|
||||
const { TuiApp } = await import('./tui/app.js');
|
||||
|
||||
render(
|
||||
React.createElement(TuiApp, {
|
||||
gatewayUrl: opts.gateway,
|
||||
conversationId: id,
|
||||
sessionCookie: session.cookie,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
sessionsCmd
|
||||
.command('destroy <id>')
|
||||
.description('Terminate an active agent session')
|
||||
.option('-g, --gateway <url>', 'Gateway URL', 'http://localhost:4000')
|
||||
.action(async (id: string, opts: { gateway: string }) => {
|
||||
const { loadSession, validateSession } = await import('./auth.js');
|
||||
const { deleteSession } = await import('./tui/gateway-api.js');
|
||||
|
||||
const session = loadSession(opts.gateway);
|
||||
if (!session) {
|
||||
console.error('Not signed in. Run `mosaic login` first.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const valid = await validateSession(opts.gateway, session.cookie);
|
||||
if (!valid) {
|
||||
console.error('Session expired. Run `mosaic login` again.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
await deleteSession(opts.gateway, session.cookie, id);
|
||||
console.log(`Session ${id} destroyed.`);
|
||||
} catch (err) {
|
||||
console.error(err instanceof Error ? err.message : String(err));
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
// ─── prdy ───────────────────────────────────────────────────────────────
|
||||
|
||||
const prdyWrapper = buildPrdyCli();
|
||||
|
||||
Reference in New Issue
Block a user