Skip to content

Run sight console on Windows, driving the Stata app - #337

Merged
jbearak merged 43 commits into
mainfrom
t3/windows-stata-com-console
Oct 31, 2026
Merged

jbearak merged 43 commits into
mainfrom
t3/windows-stata-com-console

Conversation

@jbearak

@jbearak jbearak commented Oct 31, 2026

Copy link
Copy Markdown
Owner

sight console didn't work on Windows: Stata for Windows has no console program to run in a terminal. Earlier attempts through COM (as in stata_kernel) took over and closed the user's open Stata.

Now the console drives the Stata application through its Automation interface, in a way that never touches a Stata it wasn't given:

  • No Stata open: the console starts one, and that Stata closes when the console ends.
  • One Stata open: the console asks before taking it over.
  • Several Stata windows open, or the open one is in use by another program: the console doesn't start, and says why.

Output comes from a log Stata writes. Prompts for blocks, programs, Mata and Python are predicted, as console Stata prints them. Lines you type are highlighted, completed and colored, as on macOS and Linux. browse opens Sight's Data Browser (sent as vview), as it does in console Stata elsewhere.

In VS Code on Windows, the integrated target and the "Stata" terminal profile open a Stata pane. It is an extension terminal that runs the console inside the extension, so there's no program to install. Its questions are dialogs. When the console can't take Stata, Sight offers to send code to the open Stata window instead, for this session or always.

macOS and Linux behave as before. The console now talks to Stata through a backend interface: the existing pseudo-terminal code on macOS and Linux, Automation on Windows.

Proof:

  • On a Windows 11 VM with Stata/MP 18 (driven by GPT-6.1 Terra through Parallels), the CLI ran under ConPTY. These passed: output and error coloring, Ctrl+C during sleep, Ctrl+D, declined and accepted take-over, --yes, two open Statas (exit 80), the lost-log notice, and Ctrl+C at foreach/program define/Mata prompts.

  • VS Code's real extension host on that VM: vscode:prepublish built console-runtime/console.js, and the host loaded it. It then checked:

    • a queued send ran once and its output appeared in the pane;
    • typing in the pane worked;
    • take-over and cancel worked, and the two-window "This session" and "Always" choices worked;
    • exit and closing the pane both closed the pane's Stata.

    Evidence is in scripts/spike/windows-com/results/.

  • The browse-as-vview change came after Terra's run. It is covered by unit tests but not yet run on Windows.

  • bun run typecheck, bun run lint and bun run check:line-endings pass. bun test ./tests passes except help-topic-coverage, which needs a local Stata install and fails the same way on main.

Reviewed with sol-loop: 2 rounds with gpt-6.1-sol. Sol verdict: approved

Created with Claude Opus 5.5 in Claude Code (T3 Code); plan reviewed by Claude Sonnet and GPT-6.1 Terra, and Windows debugging and verification by GPT-6.1 Terra.

Reviewed plan for driving a Stata GUI instance through COM, plus a
handoff prompt for running the Phase 0 spike on Windows.
Releasing a COM reference quits Stata, so the console owns the one
Stata it connects to for its whole life: a new one, or the single open
one after asking. Blocks and Mata keep Stata busy, so completion there
uses the echo and a quiet log.

Also correct how send-to-stata reaches Stata on Windows.
The session now talks to a StataBackend instead of the PTY directly,
and run_interactive takes a backend factory with a lifecycle. The PTY
backend keeps today's behavior: echo detection, the canonical-mode
line cap, --more-- answers, and SIGHUP-then-SIGKILL shutdown. The
session gains show_notice, write_sight_text and handle_stata_error for
backends that report outside Stata's output.

On Windows the shutdown signals include SIGBREAK instead of SIGQUIT.
The Windows integrated target will run sight console from the
extension, so vscode:prepublish now builds client/cli/cli.js as a
CommonJS bundle with the command caches, like copy-server. src/cli.ts
takes its own path from import.meta.url, which esbuild leaves empty
in CJS, so the bundle defines it from the main module's path. A build
test runs the bundle with console --help rather than only checking
that it exists.
On local Windows the Stata terminal (profile and integrated target)
now runs the extension's CLI bundle under Code.exe with
ELECTRON_RUN_AS_NODE, SIGHT_CONSOLE_FROM_EDITOR and a per-terminal
SIGHT_CONSOLE_READY_FILE. The ready file, not the process ID, marks
readiness: sends made before it appears are queued with their temp
files and typed in order once it does, with no 5 s timeout.

When the console exits without taking Stata (codes 80-86), the
extension offers send-to-stata instead (This session, Always, Cancel),
one offer at a time; code 82 (the user's s answer) dispatches at once.
Other closes drop pending sends with a notice, except a user close.
resolve_effective_target no longer falls back to the app with a
warning; it uses the app only under the session override. Callers
skip temp-file cleanup for queued sends, since the queue owns them.
Turns Stata's text log into the byte stream console Stata would
produce: prompts predicted by a mode tracker, echoes replaced by the
line as submitted, two completion rules (free and settled at top
level; echo then quiet while Stata awaits block, program, Mata or
Python input), a typeahead FIFO, log-loss detection and synthetic
echoes. Tested against a fake COM bridge with the spike's log forms.
On Windows, sight console starts a PowerShell bridge that holds one
COM reference to Stata, connects (asking before taking over an open
Stata, refusing when several are open, ending at once when the open
one is held elsewhere), marks the window, sets up a log, and runs the
interactive front end on the Automation backend. Consoles take turns
through a named mutex and mark their Stata with a pid file. Exit codes
80-86 report each case where the console didn't take Stata, for
editors to offer send-to-stata instead. Adds --yes.

The PowerShell bridge is untested here (no Windows); it runs under
Windows PowerShell 5.1 with -Sta -ExecutionPolicy Bypass -File.
Extend the integrated-terminal vscode mock with exit statuses,
profile providers, settings, notifications and a status bar item, and
cover: the profile and terminal options (ELECTRON_RUN_AS_NODE and the
ready file), sends queued until readiness and typed in order, a
profile-opened console, This session / Always / Cancel, code 82, a
helper failure, closes that make no offer, a late ready file, and a
send from the editor whose temp file is left to the queue.

Concurrent sends on Windows now queue in call order: the console
terminal is created synchronously, so joiners used to skip the await
the creating send was still in and queue ahead of it.

Bun fixes a mocked module's export names at the first mock.module
call, so the vscode enums these tests need are spread into every
vscode mock in the suite from a shared helper.
docs/send-to-stata.md: integrated runs sight console on native
Windows, sends wait for its first prompt, and the cases where it
can't take Stata lead to an offer to use the Stata GUI (This session,
Always, Cancel, and the console's s answer). auto still uses the GUI.
Note that send-to-stata picks one window itself when several are
open.
If sendText throws while queued sends are typed (the terminal went
away before its close event), drop the rest and say so instead of
leaving their temp files. VS Code before 1.77 sets no exit reason;
treat an exit code there as a process exit so codes 80-86 still
offer send-to-stata.
Stata's Automation break doesn't leave an open foreach, program, Mata
or Python block (found debugging on Windows), so the console no longer
assumes it did: Ctrl+C at a block prompt sends nothing and says how to
finish the block, and a break with a line in flight keeps the
predicted mode inside a block. A dead helper now says Stata's window
may still be open, since it stayed open in that test.
Split the console's terminal wiring into a session host that any
display can drive, and the Windows startup into open_automation_console,
shared by the CLI and a new editor entry point (start_editor_console)
that an extension can run in its own process. Connect questions are
now structured, so the CLI asks [y/N] and an editor can show a dialog.
Console history on Windows now lives under APPDATA, as documented.
VS Code's Code.exe gets no OS console on Windows, so the terminal
running sight console under it couldn't work (found debugging on
Windows). The extension now loads the console runtime into its own
process and shows it in an extension terminal (a Stata pane): keys go
in through the pane, bytes come out, and the take-over question is a
modal dialog. The queue, the offer and the session override are
unchanged; readiness and the console's end are reported directly, so
the ready file, the CLI bundle and exit-status parsing are gone.

Adds a handoff for verifying the pane on Windows.
The Windows console drives the Stata GUI, whose built-in browse
opens the Data Editor in the Stata window, so nothing showed in
the editor. Console Stata elsewhere gets vview through browse.ado;
the Windows console now rewrites browse (and br..brows, after
capture/quietly/noisily) itself when vview is installed, and says
once why nothing shows when it isn't.
…console

# Conflicts:
#	client/package.json
#	tests/unit/data-browser/restore-cancel.test.ts
@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@jbearak
jbearak merged commit 5b1d3c4 into main Oct 31, 2026
13 of 14 checks passed
@jbearak
jbearak deleted the t3/windows-stata-com-console branch October 31, 2026 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants