feat: 自动恢复会话退出后回到 Bash

This commit is contained in:
Codex
2026-07-11 07:58:20 +02:00
parent 3813ed4629
commit f52186dbe0
2 changed files with 13 additions and 5 deletions
+9 -5
View File
@@ -56,7 +56,7 @@ interface WebtermTarget {
privileged: boolean;
pid: "host" | "container";
sourceMounts: Array<{ source: string; target: string; readOnly: boolean }>;
autoStartSessions: Array<{ title: string; cwd: string; command: string; cols: number; rows: number; resumePrompt: boolean }>;
autoStartSessions: Array<{ title: string; cwd: string; command: string; cols: number; rows: number; resumePrompt: boolean; fallbackShell: boolean }>;
sessionStartModes: SessionStartModes;
autoResumePrompt: AutoResumePrompt;
environment: Record<string, string>;
@@ -370,11 +370,14 @@ function resumeCommandWithPrompt(
session: WebtermTarget["runtime"]["autoStartSessions"][number],
prompt: AutoResumePrompt,
): string {
if (!session.resumePrompt) return session.command;
if (!/^\s*(?:mycx|oncx)\s+resume\s+\S+\s*$/.test(session.command)) {
throw new Error(`resumePrompt requires a mycx/oncx resume command: ${session.title}`);
let command = session.command.trim();
if (session.resumePrompt) {
if (!/^\s*(?:mycx|oncx)\s+resume\s+\S+\s*$/.test(session.command)) {
throw new Error(`resumePrompt requires a mycx/oncx resume command: ${session.title}`);
}
command = `${command} ${quoteShellArg(prompt.prompt)}`;
}
return `${session.command.trim()} ${quoteShellArg(prompt.prompt)}`;
return session.fallbackShell ? `${command}; exec /bin/bash -l` : command;
}
function quoteShellArg(value: string): string {
@@ -554,6 +557,7 @@ function parseAutoStartSessions(value: unknown, path: string): WebtermTarget["ru
cols: integerField(record, "cols", itemPath),
rows: integerField(record, "rows", itemPath),
resumePrompt: booleanField(record, "resumePrompt", itemPath),
fallbackShell: booleanField(record, "fallbackShell", itemPath),
};
});
}