@xevy/cli 0.1.19 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/dev-session.mjs +52 -44
- package/package.json +1 -1
package/bin/dev-session.mjs
CHANGED
|
@@ -13,10 +13,8 @@ const HEARTBEAT_INTERVAL_MS = 60_000;
|
|
|
13
13
|
const SESSION_POLL_INTERVAL_MS = 2_000;
|
|
14
14
|
const SESSION_START_TIMEOUT_MS = 10 * 60_000;
|
|
15
15
|
const EXECUTION_RECONNECT_LIMIT = 8;
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const TERMINAL_RESTART_GRACE_MS = 3_000;
|
|
19
|
-
const TERMINAL_STABLE_RUNTIME_MS = 10_000;
|
|
16
|
+
const TERMINAL_START_ATTEMPT_LIMIT = 8;
|
|
17
|
+
const TERMINAL_START_MAX_DELAY_MS = 5_000;
|
|
20
18
|
const TERMINAL_SPINNER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
21
19
|
const DEV_TARGET_SEGMENT_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
22
20
|
|
|
@@ -647,6 +645,7 @@ async function attachNativeTerminal({
|
|
|
647
645
|
output,
|
|
648
646
|
signal,
|
|
649
647
|
onReady,
|
|
648
|
+
reattachHint,
|
|
650
649
|
WebSocketImpl = WebSocket,
|
|
651
650
|
}) {
|
|
652
651
|
const ticket = await api.request(`${sessionPath}/terminal-ticket`, { method: "POST", body: {}, signal });
|
|
@@ -662,6 +661,7 @@ async function attachNativeTerminal({
|
|
|
662
661
|
let ready = false;
|
|
663
662
|
let settled = false;
|
|
664
663
|
let rawEnabled = false;
|
|
664
|
+
let resumedInput = false;
|
|
665
665
|
let detachedByUser = false;
|
|
666
666
|
const connectedAt = Date.now();
|
|
667
667
|
const pendingOutput = [];
|
|
@@ -678,6 +678,13 @@ async function attachNativeTerminal({
|
|
|
678
678
|
process.off("SIGWINCH", onResize);
|
|
679
679
|
signal?.removeEventListener("abort", onAbort);
|
|
680
680
|
if (rawEnabled && typeof input.setRawMode === "function") input.setRawMode(false);
|
|
681
|
+
// A resumed stdin keeps its libuv handle referenced, so without this the
|
|
682
|
+
// process sits there after detaching and never gives the shell back.
|
|
683
|
+
if (resumedInput) {
|
|
684
|
+
input.pause?.();
|
|
685
|
+
input.unref?.();
|
|
686
|
+
resumedInput = false;
|
|
687
|
+
}
|
|
681
688
|
if (error) reject(error);
|
|
682
689
|
else resolve(result);
|
|
683
690
|
};
|
|
@@ -699,6 +706,7 @@ async function attachNativeTerminal({
|
|
|
699
706
|
socket.send(value.subarray(0, detachAt), { binary: true });
|
|
700
707
|
}
|
|
701
708
|
output.write("\r\nDetached. Pi and the Dev Session are still running.\r\n");
|
|
709
|
+
if (reattachHint) output.write(`${reattachHint}\r\n`);
|
|
702
710
|
socket.close(1000, "client_detach");
|
|
703
711
|
finish(null, { reason: "detached", code: 1000, durationMs: Date.now() - connectedAt });
|
|
704
712
|
return;
|
|
@@ -730,6 +738,7 @@ async function attachNativeTerminal({
|
|
|
730
738
|
rawEnabled = true;
|
|
731
739
|
}
|
|
732
740
|
input.resume?.();
|
|
741
|
+
resumedInput = true;
|
|
733
742
|
input.on("data", onInput);
|
|
734
743
|
process.on("SIGWINCH", onResize);
|
|
735
744
|
sendResize();
|
|
@@ -752,10 +761,18 @@ async function attachNativeTerminal({
|
|
|
752
761
|
});
|
|
753
762
|
}
|
|
754
763
|
|
|
755
|
-
|
|
764
|
+
/**
|
|
765
|
+
* Attaches once and returns when the attachment ends — by Ctrl+], because Pi
|
|
766
|
+
* exited, or because the connection dropped. It does NOT reconnect: silently
|
|
767
|
+
* restarting the remote terminal fought whoever was trying to leave and hid
|
|
768
|
+
* why Pi stopped. Retries before the first attach are a different thing and
|
|
769
|
+
* stay, since a session that is still provisioning has nothing to attach to.
|
|
770
|
+
*/
|
|
771
|
+
async function attachNativeTerminalOnce({
|
|
756
772
|
api,
|
|
757
773
|
base,
|
|
758
774
|
sessionPath,
|
|
775
|
+
reattachHint,
|
|
759
776
|
input,
|
|
760
777
|
output,
|
|
761
778
|
signal,
|
|
@@ -765,12 +782,10 @@ async function attachNativeTerminalPersistently({
|
|
|
765
782
|
animateStatus,
|
|
766
783
|
}) {
|
|
767
784
|
const status = createTerminalStatus({ output, writeLine, animate: animateStatus });
|
|
768
|
-
let
|
|
769
|
-
let consecutiveFailures = 0;
|
|
785
|
+
let attempts = 0;
|
|
770
786
|
try {
|
|
771
787
|
while (!signal?.aborted) {
|
|
772
|
-
|
|
773
|
-
status.update(reconnecting ? "Restarting remote Pi terminal…" : "Starting remote Pi terminal…");
|
|
788
|
+
status.update(attempts === 0 ? "Starting remote Pi terminal…" : "Terminal is not ready yet · retrying…");
|
|
774
789
|
try {
|
|
775
790
|
const result = await attachNativeTerminal({
|
|
776
791
|
api,
|
|
@@ -779,47 +794,36 @@ async function attachNativeTerminalPersistently({
|
|
|
779
794
|
input,
|
|
780
795
|
output,
|
|
781
796
|
signal,
|
|
782
|
-
|
|
797
|
+
reattachHint,
|
|
798
|
+
onReady: () => status.succeed("Pi terminal ready"),
|
|
783
799
|
WebSocketImpl,
|
|
784
800
|
});
|
|
785
801
|
if (result?.reason === "detached") return;
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
reconnectDelayMs = TERMINAL_RESTART_GRACE_MS;
|
|
794
|
-
status.update("Pi exited · restarting in 3 seconds · Ctrl+C to detach");
|
|
795
|
-
}
|
|
802
|
+
status.stop();
|
|
803
|
+
// The attachment ended on its own; say why and leave the session up.
|
|
804
|
+
writeLine(result?.reason === "transport-lost"
|
|
805
|
+
? "\nConnection to the Dev Session terminal was lost. The Dev Session is still running."
|
|
806
|
+
: "\nPi exited. The Dev Session is still running.");
|
|
807
|
+
if (reattachHint) writeLine(reattachHint);
|
|
808
|
+
return;
|
|
796
809
|
} catch (error) {
|
|
797
810
|
if (signal?.aborted) throw error;
|
|
798
811
|
if (error instanceof DevSessionApiError && ![409, 502, 503, 504].includes(error.status)) throw error;
|
|
799
|
-
|
|
800
|
-
|
|
812
|
+
attempts += 1;
|
|
813
|
+
if (attempts >= TERMINAL_START_ATTEMPT_LIMIT) {
|
|
814
|
+
throw new Error("The remote Pi terminal never became ready. The Dev Session remains active; check its logs and rerun `xevy dev` after correcting the startup error.");
|
|
815
|
+
}
|
|
801
816
|
status.update("Terminal is not ready yet · retrying…");
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
let current = null;
|
|
813
|
-
try {
|
|
814
|
-
current = await api.request(`${sessionPath}/`, { signal });
|
|
815
|
-
} catch (error) {
|
|
816
|
-
if (signal?.aborted) throw error;
|
|
817
|
-
if (error instanceof DevSessionApiError && [401, 403, 404].includes(error.status)) throw error;
|
|
818
|
-
status.update("Session status unavailable · retrying terminal…");
|
|
819
|
-
}
|
|
820
|
-
if (current && !current.session) throw new Error("The Dev Session disappeared while reconnecting the terminal.");
|
|
821
|
-
if (current?.session && SESSION_TERMINAL_STATUSES.has(current.session.status)) {
|
|
822
|
-
throw new Error(current.session.error || `Dev Session ${current.session.status}.`);
|
|
817
|
+
await sleep(Math.min(500 * 2 ** (attempts - 1), TERMINAL_START_MAX_DELAY_MS), signal);
|
|
818
|
+
const current = await api.request(`${sessionPath}/`, { signal }).catch((cause) => {
|
|
819
|
+
if (signal?.aborted || (cause instanceof DevSessionApiError && [401, 403, 404].includes(cause.status))) throw cause;
|
|
820
|
+
status.update("Session status unavailable · retrying terminal…");
|
|
821
|
+
return null;
|
|
822
|
+
});
|
|
823
|
+
if (current && !current.session) throw new Error("The Dev Session disappeared while starting the terminal.");
|
|
824
|
+
if (current?.session && SESSION_TERMINAL_STATUSES.has(current.session.status)) {
|
|
825
|
+
throw new Error(current.session.error || `Dev Session ${current.session.status}.`);
|
|
826
|
+
}
|
|
823
827
|
}
|
|
824
828
|
}
|
|
825
829
|
} finally {
|
|
@@ -1081,10 +1085,14 @@ export async function runDevSession(options) {
|
|
|
1081
1085
|
const nativeTerminal = options.nativeTerminal
|
|
1082
1086
|
?? (input === process.stdin && output === process.stdout);
|
|
1083
1087
|
if (interactive && nativeTerminal) {
|
|
1084
|
-
|
|
1088
|
+
const reattachTarget = context.kind === "task"
|
|
1089
|
+
? `task/${task.taskCode || task.id}`
|
|
1090
|
+
: `${context.workspace.identifier}/${context.project.identifier}`;
|
|
1091
|
+
await attachNativeTerminalOnce({
|
|
1085
1092
|
api,
|
|
1086
1093
|
base,
|
|
1087
1094
|
sessionPath,
|
|
1095
|
+
reattachHint: `Reattach with: xevy dev ${reattachTarget}`,
|
|
1088
1096
|
input,
|
|
1089
1097
|
output,
|
|
1090
1098
|
signal: detachController.signal,
|
package/package.json
CHANGED