fix: 启动恢复会话时直接传入提示
This commit is contained in:
@@ -334,7 +334,10 @@ function resolveTarget(targetId: string | null): WebtermTarget {
|
||||
function renderCompose(target: WebtermTarget): string {
|
||||
const environment = {
|
||||
...target.runtime.environment,
|
||||
AUTO_START_SESSIONS_JSON: JSON.stringify(target.runtime.autoStartSessions),
|
||||
AUTO_START_SESSIONS_JSON: JSON.stringify(target.runtime.autoStartSessions.map((session) => ({
|
||||
...session,
|
||||
command: resumeCommandWithPrompt(session, target.runtime.autoResumePrompt),
|
||||
}))),
|
||||
SESSION_START_MODES_JSON: JSON.stringify(target.runtime.sessionStartModes.options),
|
||||
SESSION_START_DEFAULT_MODE: target.runtime.sessionStartModes.defaultMode,
|
||||
AUTO_RESUME_PROMPT_JSON: JSON.stringify(target.runtime.autoResumePrompt),
|
||||
@@ -365,6 +368,21 @@ ${envLines}
|
||||
`;
|
||||
}
|
||||
|
||||
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}`);
|
||||
}
|
||||
return `${session.command.trim()} ${quoteShellArg(prompt.prompt)}`;
|
||||
}
|
||||
|
||||
function quoteShellArg(value: string): string {
|
||||
return `'${value.replace(/'/g, `'"'"'`)}'`;
|
||||
}
|
||||
|
||||
function policyChecks(target: WebtermTarget, compose: string): Array<Record<string, unknown> & { ok: boolean }> {
|
||||
return [
|
||||
{ name: "enabled", ok: target.enabled, detail: "target must be enabled" },
|
||||
|
||||
Reference in New Issue
Block a user