Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/adapters/claude-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ export class ClaudeCodeAdapter implements AgentAdapter {
resolvedSessionId = await this.pollForSessionId(logPath, pid, 5000);
}

const sessionId = resolvedSessionId || crypto.randomUUID();
const sessionId =
resolvedSessionId || (pid ? `pending-${pid}` : crypto.randomUUID());

// Persist session metadata so status checks work after wrapper exits
if (pid) {
Expand Down
46 changes: 46 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,52 @@ program
}
});

// kill
program
.command("kill <id>")
.description("Remove a session record from the store")
.option("--force", "Force remove regardless of state (SIGKILL if running)")
.action(async (id: string, opts) => {
const daemonRunning = await ensureDaemon();
if (!daemonRunning) {
console.error("Daemon not running");
process.exit(1);
}
try {
await client.call("session.kill", { id, force: opts.force });
console.log(`Removed session ${id.slice(0, 8)}`);
} catch (err) {
console.error((err as Error).message);
process.exit(1);
}
});

// prune
program
.command("prune")
.description("Remove stale stopped sessions")
.option(
"--max-age <hours>",
"Remove sessions stopped more than N hours ago",
"24",
)
.action(async (opts) => {
const daemonRunning = await ensureDaemon();
if (!daemonRunning) {
console.error("Daemon not running");
process.exit(1);
}
try {
const result = await client.call<{ pruned: number }>("session.prune", {
maxAgeHours: Number(opts.maxAge),
});
console.log(`Pruned ${result.pruned} stale session(s)`);
} catch (err) {
console.error((err as Error).message);
process.exit(1);
}
});

// resume
program
.command("resume <id> <message>")
Expand Down
33 changes: 33 additions & 0 deletions src/daemon/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,39 @@ function createRequestHandler(ctx: HandlerContext) {
return null;
}

case "session.kill": {
const session = ctx.sessionTracker.getSession(params.id as string);
if (!session) throw new Error(`Session not found: ${params.id}`);
const force = params.force as boolean | undefined;

// If session is still running, try to stop the process first
if (session.status === "running" || session.status === "idle") {
if (session.pid) {
try {
process.kill(session.pid, force ? "SIGKILL" : "SIGTERM");
} catch {
// Already dead
}
}
}

// Remove auto-lock
ctx.lockManager.autoUnlock(session.id);

// Remove session record from store
ctx.sessionTracker.removeSession(session.id);
ctx.metrics.recordSessionStopped();

return null;
}

case "session.prune": {
const maxAgeMs =
((params.maxAgeHours as number) || 24) * 60 * 60 * 1000;
const pruned = ctx.sessionTracker.pruneSessions(maxAgeMs);
return { pruned };
}

case "session.resume": {
const session = ctx.sessionTracker.getSession(params.id as string);
if (!session) throw new Error(`Session not found: ${params.id}`);
Expand Down
Loading