mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-17 04:45:33 -08:00
Offer a reconnect button when a loop phase's page does not show
AI Assisted
This commit is contained in:
1 parent
f5369df090
commit
bb66f1d458
3 files changed
+79
-6
No files matched your search
+39
-5
@@ -3,7 +3,7 @@
|
|||||||
// request) with a drag handle.
|
// request) with a drag handle.
|
||||||
|
|
||||||
import { mountTerminal } from './terminal.js';
|
import { mountTerminal } from './terminal.js';
|
||||||
import { NEW_RELEASE_COMMAND, attentionSignal, barNextSteps, continueKeys, defaultRightFraction, folderName, lastAgentNotice, pickDefaultAgent, taskbarSwitch, windowTitleFor, deadConsoleAction, loopBanner, loopLocks, loopStopLabels, loopWindowTitle } from './meter.js';
|
import { NEW_RELEASE_COMMAND, attentionSignal, barNextSteps, continueKeys, defaultRightFraction, folderName, lastAgentNotice, pickDefaultAgent, taskbarSwitch, windowTitleFor, deadConsoleAction, loopBanner, loopLocks, loopStopLabels, loopWindowTitle, helloRetryAction, retryLabel, RETRY_AFTER_SECONDS } from './meter.js';
|
||||||
|
|
||||||
const { invoke, Channel } = window.__TAURI__.core;
|
const { invoke, Channel } = window.__TAURI__.core;
|
||||||
|
|
||||||
@@ -910,8 +910,13 @@ async function onNoHello() {
|
|||||||
if (frameReady || !consoleKnown || restarting) return;
|
if (frameReady || !consoleKnown || restarting) return;
|
||||||
// A page that does not answer cannot say it is done needing the person.
|
// A page that does not answer cannot say it is done needing the person.
|
||||||
clearAttention();
|
clearAttention();
|
||||||
// The next phase's console is on its way; the poll says so instead.
|
// The next phase's console is on its way; the poll says so instead. Look
|
||||||
if (loopRunning && loopStep === 'Starting') return;
|
// again later all the same: dropped for good, a page that never said hello
|
||||||
|
// left its message on screen with no way out once the step moved on.
|
||||||
|
if (helloRetryAction({ loopRunning, loopStep }) === 'rearm') {
|
||||||
|
helloTimer = setTimeout(onNoHello, HELLO_WAIT_MS);
|
||||||
|
return;
|
||||||
|
}
|
||||||
let status = null;
|
let status = null;
|
||||||
try {
|
try {
|
||||||
status = await invoke('console_status');
|
status = await invoke('console_status');
|
||||||
@@ -928,7 +933,21 @@ async function onNoHello() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function showState(text, buttonLabel, onButton, onCancel, { tired = false } = {}) {
|
// A waiting message that offers a way out after a countdown: the button shows
|
||||||
|
// disabled, counting down, then turns into `buttonLabel`'s plain retry.
|
||||||
|
let retryTimer = null;
|
||||||
|
|
||||||
|
function stopRetryCountdown() {
|
||||||
|
clearInterval(retryTimer);
|
||||||
|
retryTimer = null;
|
||||||
|
stateButton.disabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function showState(text, buttonLabel, onButton, onCancel, { tired = false, retryAfter = 0 } = {}) {
|
||||||
|
// The poll repeats the same waiting message every tick: that must not
|
||||||
|
// restart a countdown that is already running (or its button).
|
||||||
|
if (retryAfter > 0 && !stateBox.hidden && stateText.textContent === text && stateButton.textContent.startsWith('Try reconnecting')) return;
|
||||||
|
stopRetryCountdown();
|
||||||
hideLaunchCard();
|
hideLaunchCard();
|
||||||
hideFirstRun();
|
hideFirstRun();
|
||||||
// statePlannyEl is an <svg>: unlike HTMLElement, it does not reflect the
|
// statePlannyEl is an <svg>: unlike HTMLElement, it does not reflect the
|
||||||
@@ -942,9 +961,20 @@ function showState(text, buttonLabel, onButton, onCancel, { tired = false } = {}
|
|||||||
stateCancelEl.hidden = !onCancel;
|
stateCancelEl.hidden = !onCancel;
|
||||||
stateCancelEl.onclick = onCancel || null;
|
stateCancelEl.onclick = onCancel || null;
|
||||||
stateBox.hidden = false;
|
stateBox.hidden = false;
|
||||||
|
if (retryAfter > 0 && buttonLabel) {
|
||||||
|
let left = retryAfter;
|
||||||
|
stateButton.disabled = true;
|
||||||
|
stateButton.textContent = retryLabel(left);
|
||||||
|
retryTimer = setInterval(() => {
|
||||||
|
left -= 1;
|
||||||
|
stateButton.textContent = retryLabel(left);
|
||||||
|
if (left <= 0) stopRetryCountdown();
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideState() {
|
function hideState() {
|
||||||
|
stopRetryCountdown();
|
||||||
stateBox.hidden = true;
|
stateBox.hidden = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -983,7 +1013,7 @@ async function pollConsole() {
|
|||||||
if (action === 'wait-for-phase') {
|
if (action === 'wait-for-phase') {
|
||||||
// Covers the old phase's page and its "Lost contact" until the new one
|
// Covers the old phase's page and its "Lost contact" until the new one
|
||||||
// says hello. Never over a question the box is already asking.
|
// says hello. Never over a question the box is already asking.
|
||||||
if (stateCancelEl.hidden) showState(loopDetailEl.textContent);
|
if (stateCancelEl.hidden) showState(loopDetailEl.textContent, 'Try reconnecting', reconnectConsole, undefined, { retryAfter: RETRY_AFTER_SECONDS });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
markConsoleDead();
|
markConsoleDead();
|
||||||
@@ -1167,6 +1197,7 @@ function applyLoopState(state) {
|
|||||||
}
|
}
|
||||||
if (!loopRunning) loopTypingNoted = false;
|
if (!loopRunning) loopTypingNoted = false;
|
||||||
loopRunning = true;
|
loopRunning = true;
|
||||||
|
const stepBefore = loopStep;
|
||||||
loopStep = state.step || '';
|
loopStep = state.step || '';
|
||||||
restartBtn.hidden = true;
|
restartBtn.hidden = true;
|
||||||
applyLoopLocks(state);
|
applyLoopLocks(state);
|
||||||
@@ -1176,6 +1207,9 @@ function applyLoopState(state) {
|
|||||||
// Only a change of words: this is a live region, and screen readers read it out.
|
// Only a change of words: this is a live region, and screen readers read it out.
|
||||||
if (loopTitleEl.textContent !== banner.title) loopTitleEl.textContent = banner.title;
|
if (loopTitleEl.textContent !== banner.title) loopTitleEl.textContent = banner.title;
|
||||||
if (loopDetailEl.textContent !== banner.detail) loopDetailEl.textContent = banner.detail;
|
if (loopDetailEl.textContent !== banner.detail) loopDetailEl.textContent = banner.detail;
|
||||||
|
// A phase starting: look at the console now, so its waiting message and
|
||||||
|
// countdown begin at once, not at the next status poll.
|
||||||
|
if (loopStep === 'Starting' && stepBefore !== 'Starting' && consoleKnown) void pollConsole();
|
||||||
loopHintEl.textContent = banner.hint;
|
loopHintEl.textContent = banner.hint;
|
||||||
loopSpecEl.textContent = state.specName || '';
|
loopSpecEl.textContent = state.specName || '';
|
||||||
loopPipsEl.replaceChildren(
|
loopPipsEl.replaceChildren(
|
||||||
|
|||||||
@@ -253,6 +253,24 @@ export function deadConsoleAction({ loopRunning, loopStep, frameReady, reconnect
|
|||||||
return reconnects < limit ? "reconnect" : "offer-button";
|
return reconnects < limit ? "reconnect" : "offer-button";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What the window does when a page's hello did not come in time. While a loop
|
||||||
|
* starts a phase the poll words the wait, so the check is not run now, but it
|
||||||
|
* must be armed again: dropped for good, a page that never says hello left the
|
||||||
|
* center message on screen with no way out once the step moved on.
|
||||||
|
*/
|
||||||
|
export function helloRetryAction({ loopRunning, loopStep }) {
|
||||||
|
return loopRunning && loopStep === "Starting" ? "rearm" : "check";
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Seconds a waiting message stays before it offers Try reconnecting. */
|
||||||
|
export const RETRY_AFTER_SECONDS = 10;
|
||||||
|
|
||||||
|
/** The retry button's label: counting down, then plain. */
|
||||||
|
export function retryLabel(secondsLeft) {
|
||||||
|
return secondsLeft > 0 ? `Try reconnecting in ${secondsLeft}s` : "Try reconnecting";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A project folder's own name, for the bar's project menu: the same last
|
* A project folder's own name, for the bar's project menu: the same last
|
||||||
* segment the window title uses, or the whole path when there is none (a
|
* segment the window title uses, or the whole path when there is none (a
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import assert from "node:assert/strict";
|
|||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { fileURLToPath, pathToFileURL } from "node:url";
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||||
import { attentionSignal, barNextSteps, continueKeys, defaultRightFraction, folderName, pickDefaultAgent, taskbarSwitch, windowTitleFor, deadConsoleAction, loopBanner, loopRunText, loopLocks, loopStopLabels, loopWindowTitle, CONSOLE_ASIDE_BREAKPOINT_PX, NEXT_STEP_LABELS, NEW_RELEASE_COMMAND } from "../plan2code-app/ui/meter.js";
|
import { helloRetryAction, retryLabel, RETRY_AFTER_SECONDS, attentionSignal, barNextSteps, continueKeys, defaultRightFraction, folderName, pickDefaultAgent, taskbarSwitch, windowTitleFor, deadConsoleAction, loopBanner, loopRunText, loopLocks, loopStopLabels, loopWindowTitle, CONSOLE_ASIDE_BREAKPOINT_PX, NEXT_STEP_LABELS, NEW_RELEASE_COMMAND } from "../plan2code-app/ui/meter.js";
|
||||||
import { findBrowser, launchBrowser } from "./browser.mjs";
|
import { findBrowser, launchBrowser } from "./browser.mjs";
|
||||||
|
|
||||||
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
||||||
@@ -423,6 +423,27 @@ test("a console dead between a loop's phases waits for the next phase; any other
|
|||||||
assert.equal(deadConsoleAction({ ...base, frameReady: false }), "no-hello");
|
assert.equal(deadConsoleAction({ ...base, frameReady: false }), "no-hello");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("a page that said no hello is looked at again while a loop starts a phase, and the retry button counts down", () => {
|
||||||
|
assert.equal(helloRetryAction({ loopRunning: true, loopStep: "Starting" }), "rearm", "the poll covers Starting, but nothing may drop the check for good");
|
||||||
|
assert.equal(helloRetryAction({ loopRunning: true, loopStep: "Build" }), "check");
|
||||||
|
assert.equal(helloRetryAction({ loopRunning: false, loopStep: "Starting" }), "check");
|
||||||
|
assert.equal(retryLabel(10), "Try reconnecting in 10s");
|
||||||
|
assert.equal(retryLabel(1), "Try reconnecting in 1s");
|
||||||
|
assert.equal(retryLabel(0), "Try reconnecting");
|
||||||
|
assert.equal(retryLabel(-3), "Try reconnecting");
|
||||||
|
assert.equal(RETRY_AFTER_SECONDS, 10);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("app.js re-arms the hello check and offers Try reconnecting on the loop's waiting message", () => {
|
||||||
|
const app = fs.readFileSync(path.join(HERE, "..", "plan2code-app", "ui", "app.js"), "utf8");
|
||||||
|
const noHello = app.slice(app.indexOf("async function onNoHello"), app.indexOf("function showState"));
|
||||||
|
assert.match(noHello, /helloRetryAction\(/);
|
||||||
|
assert.match(noHello, /setTimeout\(onNoHello, HELLO_WAIT_MS\)/, "a swallowed hello check is armed again");
|
||||||
|
assert.match(app, /showState\(loopDetailEl\.textContent[^)]*retryAfter/s, "the loop's wait for a phase's page offers the button");
|
||||||
|
assert.doesNotMatch(app, /showState\('Opening the page'[^)]*retryAfter/s, "onNoHello swaps that message at 8s, so a 10s countdown there never finishes");
|
||||||
|
assert.match(app, /loopStep === 'Starting' && stepBefore !== 'Starting' && consoleKnown\) void pollConsole\(\)/, "a phase starting looks at the console at once, so the countdown does not wait for the next poll");
|
||||||
|
});
|
||||||
|
|
||||||
test("app.js refills the reconnect budget on a new page and brings the page back when a loop ends", () => {
|
test("app.js refills the reconnect budget on a new page and brings the page back when a loop ends", () => {
|
||||||
const app = fs.readFileSync(path.join(HERE, "..", "plan2code-app", "ui", "app.js"), "utf8");
|
const app = fs.readFileSync(path.join(HERE, "..", "plan2code-app", "ui", "app.js"), "utf8");
|
||||||
const announced = app.slice(app.indexOf("function showAnnounced"), app.indexOf("window.__TAURI__.event.listen('console-page'"));
|
const announced = app.slice(app.indexOf("function showAnnounced"), app.indexOf("window.__TAURI__.event.listen('console-page'"));
|
||||||
|
|||||||
Reference in new issue
Block a user