66 describeReadinessCause ,
77 waitForHttpReady as waitForHttpReadyShared ,
88} from "@t3tools/shared/httpReadiness" ;
9+ import { CLI_RELEASE_REPOSITORY } from "@t3tools/shared/cliRelease" ;
910import * as NetService from "@t3tools/shared/Net" ;
1011import { extractJsonObject , fromLenientJson } from "@t3tools/shared/schemaJson" ;
1112import { satisfiesSemverRange } from "@t3tools/shared/semver" ;
@@ -62,6 +63,12 @@ export interface RemoteT3RunnerOptions {
6263 readonly packageSpec ?: string ;
6364 readonly nodeScriptPath ?: string | null ;
6465 readonly nodeEngineRange ?: string | null ;
66+ /**
67+ * Exact version whose release archive the remote installs and runs. Takes
68+ * precedence over `packageSpec`; the remote then needs neither Node nor npm.
69+ */
70+ readonly archiveVersion ?: string | null ;
71+ readonly releaseBaseUrl ?: string | null ;
6572}
6673
6774export interface SshEnvironmentManagerOptions {
@@ -108,6 +115,9 @@ function sshTargetLogFields(target: DesktopSshEnvironmentTarget) {
108115}
109116
110117function sshRunnerLogFields ( runner : RemoteT3RunnerOptions | undefined ) {
118+ if ( runner ?. archiveVersion ?. trim ( ) ) {
119+ return { runner : "archive" , archiveVersion : runner . archiveVersion . trim ( ) } ;
120+ }
111121 if ( runner ?. nodeScriptPath ?. trim ( ) ) {
112122 return { runner : "node-script" , nodeScriptPath : runner . nodeScriptPath . trim ( ) } ;
113123 }
@@ -404,6 +414,53 @@ ensure_remote_node_path() {
404414
405415const REMOTE_RUNNER_SCRIPT = `#!/bin/sh
406416set -eu
417+ T3_ARCHIVE_VERSION=@@T3_ARCHIVE_VERSION@@
418+ if [ -n "$T3_ARCHIVE_VERSION" ]; then
419+ # Self-contained release archive: no Node, npm, or compiler on the remote.
420+ # Unpacked into the pinned-runtime layout so \`t3 service install\` reuses it.
421+ T3_RELEASE_BASE_URL=@@T3_RELEASE_BASE_URL@@
422+ T3_RUNTIME_DIR="$HOME/.t3/runtime/versions/$T3_ARCHIVE_VERSION"
423+ if [ ! -x "$T3_RUNTIME_DIR/t3" ] || [ "$(cat "$T3_RUNTIME_DIR/.install-complete" 2>/dev/null)" != "$T3_ARCHIVE_VERSION" ]; then
424+ case "$(uname -s)" in
425+ Darwin) T3_PLATFORM="darwin" ;;
426+ Linux) T3_PLATFORM="linux" ;;
427+ *) printf 'Remote host %s has no t3 release archive.\\n' "$(uname -s)" >&2; exit 1 ;;
428+ esac
429+ case "$(uname -m)" in
430+ arm64 | aarch64) T3_ARCH="arm64" ;;
431+ x86_64 | amd64) T3_ARCH="x64" ;;
432+ *) printf 'Remote host %s has no t3 release archive.\\n' "$(uname -m)" >&2; exit 1 ;;
433+ esac
434+ T3_ARCHIVE="t3-$T3_ARCHIVE_VERSION-$T3_PLATFORM-$T3_ARCH.tar.gz"
435+ mkdir -p "$HOME/.t3/runtime/versions"
436+ T3_STAGING="$(mktemp -d "$HOME/.t3/runtime/versions/.staging-XXXXXX")"
437+ trap 'rm -rf "$T3_STAGING"' EXIT
438+ t3_fetch() {
439+ if command -v curl >/dev/null 2>&1; then curl -fsSL "$1" -o "$2"
440+ elif command -v wget >/dev/null 2>&1; then wget -q "$1" -O "$2"
441+ else printf 'Remote host needs curl or wget to download %s.\\n' "$T3_ARCHIVE" >&2; exit 1
442+ fi
443+ }
444+ t3_fetch "$T3_RELEASE_BASE_URL/v$T3_ARCHIVE_VERSION/SHA256SUMS" "$T3_STAGING/SHA256SUMS"
445+ t3_fetch "$T3_RELEASE_BASE_URL/v$T3_ARCHIVE_VERSION/$T3_ARCHIVE" "$T3_STAGING/$T3_ARCHIVE"
446+ T3_EXPECTED="$(grep " \\*\\{0,1\\}$T3_ARCHIVE$" "$T3_STAGING/SHA256SUMS" | cut -d' ' -f1)"
447+ if command -v sha256sum >/dev/null 2>&1; then
448+ T3_ACTUAL="$(sha256sum "$T3_STAGING/$T3_ARCHIVE" | cut -d' ' -f1)"
449+ else
450+ T3_ACTUAL="$(shasum -a 256 "$T3_STAGING/$T3_ARCHIVE" | cut -d' ' -f1)"
451+ fi
452+ if [ -z "$T3_EXPECTED" ] || [ "$T3_ACTUAL" != "$T3_EXPECTED" ]; then
453+ printf 'Checksum mismatch for %s.\\n' "$T3_ARCHIVE" >&2; exit 1
454+ fi
455+ tar -xzf "$T3_STAGING/$T3_ARCHIVE" -C "$T3_STAGING" --strip-components=1
456+ rm -f "$T3_STAGING/$T3_ARCHIVE" "$T3_STAGING/SHA256SUMS"
457+ printf '%s\\n' "$T3_ARCHIVE_VERSION" > "$T3_STAGING/.install-complete"
458+ rm -rf "$T3_RUNTIME_DIR"
459+ mv "$T3_STAGING" "$T3_RUNTIME_DIR"
460+ trap - EXIT
461+ fi
462+ exec "$T3_RUNTIME_DIR/t3" "$@"
463+ fi
407464@@T3_NODE_ENV_SCRIPT@@
408465ensure_remote_node_path || true
409466T3_NODE_SCRIPT_PATH=@@T3_NODE_SCRIPT_PATH@@
@@ -473,16 +530,30 @@ if [ ! -f "$RUNNER_FILE" ] || ! cmp -s "$RUNNER_NEXT" "$RUNNER_FILE"; then
473530fi
474531mv "$RUNNER_NEXT" "$RUNNER_FILE"
475532chmod 700 "$RUNNER_FILE"
476- if ! ensure_remote_node_path; then
533+ T3_ARCHIVE_MODE=@@T3_ARCHIVE_MODE@@
534+ if [ "$T3_ARCHIVE_MODE" = "1" ]; then
535+ # The archive ships the helpers below inside the executable; the remote
536+ # needs no Node at all. Resolving the runner once here also downloads the
537+ # archive before the port and readiness probes rely on it.
538+ "$RUNNER_FILE" --version >/dev/null
539+ elif ! ensure_remote_node_path; then
477540 printf 'Remote host is missing node on PATH. Install Node or configure a supported version manager for non-interactive shells.\\n' >&2
478541 exit 1
479542fi
480543pick_port() {
544+ if [ "$T3_ARCHIVE_MODE" = "1" ]; then
545+ "$RUNNER_FILE" __ssh-helper pick-port "$PORT_FILE" "@@T3_DEFAULT_REMOTE_PORT@@" "@@T3_REMOTE_PORT_SCAN_WINDOW@@"
546+ return
547+ fi
481548 node - "$PORT_FILE" "@@T3_DEFAULT_REMOTE_PORT@@" "@@T3_REMOTE_PORT_SCAN_WINDOW@@" <<'NODE'
482549@@T3_PICK_PORT_SCRIPT@@
483550NODE
484551}
485552wait_ready() {
553+ if [ "$T3_ARCHIVE_MODE" = "1" ]; then
554+ "$RUNNER_FILE" __ssh-helper wait-ready "$REMOTE_PORT" "$1" "@@T3_READY_PROBE_TIMEOUT_MS@@"
555+ return
556+ fi
486557 node - "$REMOTE_PORT" "$1" "@@T3_READY_PROBE_TIMEOUT_MS@@" <<'NODE'
487558@@T3_WAIT_READY_SCRIPT@@
488559NODE
@@ -496,6 +567,10 @@ wait_for_pid_exit() {
496567 done
497568}
498569resolve_default_runtime_port() {
570+ if [ "$T3_ARCHIVE_MODE" = "1" ]; then
571+ "$RUNNER_FILE" __ssh-helper runtime-port "$DEFAULT_RUNTIME_FILE"
572+ return
573+ fi
499574 node - "$DEFAULT_RUNTIME_FILE" <<'NODE'
500575const fs = require("node:fs");
501576const runtimePath = process.argv[2] ?? "";
653728export function buildRemoteT3RunnerScript ( input ?: RemoteT3RunnerOptions ) : string {
654729 const packageSpec = shellSingleQuote ( input ?. packageSpec ?. trim ( ) || "t3@latest" ) ;
655730 const nodeScriptPath = input ?. nodeScriptPath ?. trim ( ) || "" ;
731+ const archiveVersion = input ?. archiveVersion ?. trim ( ) || "" ;
732+ const releaseBaseUrl =
733+ input ?. releaseBaseUrl ?. trim ( ) . replace ( / \/ + $ / u, "" ) ||
734+ `https://github.com/${ CLI_RELEASE_REPOSITORY } /releases/download` ;
656735 return stripTrailingNewlines (
657736 applyScriptPlaceholders ( REMOTE_RUNNER_SCRIPT , {
658737 T3_PACKAGE_SPEC : packageSpec ,
659738 T3_NODE_SCRIPT_PATH : shellSingleQuote ( nodeScriptPath ) ,
739+ T3_ARCHIVE_VERSION : shellSingleQuote ( archiveVersion ) ,
740+ T3_RELEASE_BASE_URL : shellSingleQuote ( releaseBaseUrl ) ,
660741 T3_NODE_ENV_SCRIPT : buildRemoteNodeEnvScript ( input ) ,
661742 } ) ,
662743 ) ;
@@ -673,6 +754,7 @@ export function buildRemoteNodeEnvScript(input?: RemoteT3RunnerOptions): string
673754
674755export function buildRemoteLaunchScript ( input ?: RemoteT3RunnerOptions ) : string {
675756 return applyScriptPlaceholders ( REMOTE_LAUNCH_SCRIPT , {
757+ T3_ARCHIVE_MODE : input ?. archiveVersion ?. trim ( ) ? "1" : "0" ,
676758 T3_NODE_ENV_SCRIPT : buildRemoteNodeEnvScript ( input ) ,
677759 T3_RUNNER_SCRIPT : stripTrailingNewlines ( buildRemoteT3RunnerScript ( input ) ) ,
678760 T3_PICK_PORT_SCRIPT : stripTrailingNewlines ( REMOTE_PICK_PORT_SCRIPT ) ,
0 commit comments