From e4e515652c55013bfcd2b0bdf006aee9fe41f7fa Mon Sep 17 00:00:00 2001 From: Julian Noble Date: Fri, 24 Jul 2026 02:19:08 +1000 Subject: [PATCH] piperepl patch rev: TCLSH_PIPEREPL_DEBUG-gated reopen notice on stderr; publish ::tclsh(reopened) (G-118 items 1+7) In-source rev of tclMain_piperepl_905.c, effective at the next suite rebuild (the G-117 cycle): the '? reopen stdin from console' notice prints only when TCLSH_PIPEREPL_DEBUG is set truthy; all reopen-path messages (gated notice + genuine failure messages) move from stdout to stderr; ::tclsh(reopened) published as an unlinked fact (0 at gate-open startup, republished 1 after a successful console reopen). 2024-era artifacts (tclMain_piperepl.c, .patch) stay unmodified per the recovery policy. Assisted-by: harness=claude; primary-model=claude-fable-5; api-location=anthropic.com --- src/buildsuites/suite_tcl90/patches/README.md | 10 ++++--- .../patches/tclMain_piperepl_905.c | 26 +++++++++++++++++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/buildsuites/suite_tcl90/patches/README.md b/src/buildsuites/suite_tcl90/patches/README.md index 57f40065..63da0a0b 100644 --- a/src/buildsuites/suite_tcl90/patches/README.md +++ b/src/buildsuites/suite_tcl90/patches/README.md @@ -51,9 +51,13 @@ that sets dorepl opts into prompts/echo in the reopened repl); and a script-arg launch from a CONSOLE READS 1 where stock reads 0 (stock sets it once to `!path && istty`; the early link overwrites that with the tty flag. Piped launches read 0 either way, so only console script runs diverge for readers - verified -against punk9_beta 2026-07-23). Known residue: on the eof-with-dorepl path the -patch unconditionally prints "? reopen stdin from console" to STDOUT (debug-era -message); quieting/stderr/env-gating it needs a patch rev + suite rebuild. Note the +against punk9_beta 2026-07-23). Patch rev 2026-07-24 (G-118 items 1+7; in-source, effective at the next suite +rebuild - the G-117 cycle): the "? reopen stdin from console" notice is emitted +only when TCLSH_PIPEREPL_DEBUG is set truthy (stock prints nothing entering a +repl), and the reopen-path messages (gated notice + genuine failure messages) +moved from stdout to STDERR; ::tclsh(reopened) is published as an unlinked fact +(0 at gate-open startup, republished 1 after a successful console reopen) - +previously inferable only via `info exists ::tclsh(inputbuffer)`. Note the punkshell-level analogue for the punk repl is G-038 (piped-to-interactive session continuity) - this patch is the plain-tclsh/kit-runtime counterpart. diff --git a/src/buildsuites/suite_tcl90/patches/tclMain_piperepl_905.c b/src/buildsuites/suite_tcl90/patches/tclMain_piperepl_905.c index 9d4ee3b7..7367a76d 100644 --- a/src/buildsuites/suite_tcl90/patches/tclMain_piperepl_905.c +++ b/src/buildsuites/suite_tcl90/patches/tclMain_piperepl_905.c @@ -412,6 +412,20 @@ Tcl_MainEx( Tcl_DStringFree(&ds); } } + int pipeReplDebug; + { + const char *s; + Tcl_DString ds; + s = TclGetEnv("TCLSH_PIPEREPL_DEBUG", &ds); + /* G-118 item 1 (2026-07-24): patch diagnostics such as the console-reopen + * notice print only when TCLSH_PIPEREPL_DEBUG is set truthy (not "0") - + * stock tclsh prints nothing when entering a repl. Genuine reopen + * FAILURES stay unconditional (now on stderr). */ + pipeReplDebug = ((s != NULL) && strcmp(s, "0")); + if (s != NULL) { + Tcl_DStringFree(&ds); + } + } piperepl.reopened = 0; piperepl.dorepl = 0; piperepl.evalinput = 0; @@ -430,6 +444,10 @@ Tcl_MainEx( Tcl_NewBooleanObj(ttyAtStart), TCL_GLOBAL_ONLY); Tcl_SetVar2Ex(interp, "tclsh", "evalinput", Tcl_NewBooleanObj(piperepl.evalinput), TCL_GLOBAL_ONLY); + //unlinked fact - republished as 1 when stdin is reopened from the + //console after eof-with-dorepl (G-118 item 7) + Tcl_SetVar2Ex(interp, "tclsh", "reopened", + Tcl_NewBooleanObj(0), TCL_GLOBAL_ONLY); } Tcl_SetVar2Ex(interp, "tcl_interactive", NULL, @@ -622,10 +640,12 @@ Tcl_MainEx( */ if (piperepl.dorepl) { - chan = Tcl_GetStdChannel(TCL_STDOUT); + chan = Tcl_GetStdChannel(TCL_STDERR); inputReopen--; if (inputReopen >= 0) { - Tcl_WriteChars(chan, "? reopen stdin from console \n", -1); + if (pipeReplDebug) { + Tcl_WriteChars(chan, "? reopen stdin from console \n", -1); + } if (is.input != NULL) { //Tcl_UnregisterChannel should close stdin without killing console? if (Tcl_UnregisterChannel(interp, is.input) != TCL_OK) { @@ -645,6 +665,8 @@ Tcl_MainEx( } else { piperepl.reopened = 1; Tcl_SetVar2Ex(interp, "tclsh", "inputbuffer", piperepl.inputbuffer, TCL_GLOBAL_ONLY); + Tcl_SetVar2Ex(interp, "tclsh", "reopened", + Tcl_NewBooleanObj(1), TCL_GLOBAL_ONLY); Tcl_SetChannelOption(interp, is.input, "-blocking", "1"); Tcl_SetChannelOption(interp, is.input, "-buffering", "line"); Tcl_SetStdChannel(is.input,TCL_STDIN);